gpt4 book ai didi

带有返回码和返回消息的 PHP 函数,仅供引用

转载 作者:行者123 更新时间:2023-11-29 22:24:44 27 4
gpt4 key购买 nike

这段 php 代码是通过 ajax 从 javascript 调用的,应该返回一个数字代码和一条消息。我可以从 PHP 脚本返回一个数组,但是当我读取 ajax 响应时,该响应包含的内容比返回的数组多,它还有其他回显语句。有没有办法从仅返回数组的 Php 发送信息?我只想要 json 对象 {"return_code":0,"return_msg":"Login successful."}

这是使用 alert(login_info); 通过 ajax 返回到 javascript 的信息。

Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the

date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in /Library/WebServer/Documents/Pagelinks_Dev/login_user.php on line 60 {"return_code":0,"return_msg":"Login successful."}

这是 ajax 调用。

var message = $.ajax({
url: "login_user.php",
type: "POST",
data: { username_email: username_email, upass: user_passwd },
cache: false,
async: false,
success: function (login_info) {
if (login_info != '')
{
alert(login_info);
}
},
error: function (request, status, error) {
alert ("status "+status+" error "+error+"responseText "+request.responseText);
},
}).responseText;

PHP脚本

<?php include("dbconnect.php"); ?>

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();

function login_user( $username_email, $password_text ) {
global $dbco;

$password = md5($password_text);
$privPost = 1; // 3: max.
$privSedit = 0;

$messages = array( 'log_no_un_em' => 'Enter username or email.',
'log_no_pw' => 'Enter password.',
'log_un_em_pw_incorrect' => 'Incorrect login info.',
'log_success' => 'Login successful.'
);

$return = array();

$l_un_em = isset($username_email) ? $username_email : '';
$l_pword = isset($password_text) ? $password_text : '';

if (!$l_un_em) {
/* echo $messages['log_no_un_em'];
return; */
$return['return_code'] = -1;
$return['return_msg'] = $messages['log_no_un_em'];
echo json_encode($return);
}
if (!$l_pword) {
/* echo $messages['log_no_pw'];
return; */
$return['return_code'] = -1;
$return['return_msg'] = $messages['log_no_pw'];
echo json_encode($return);
}

mysql_select_db("luxcal", $dbco);

while (true) {
$md5_pw = md5($password_text);
$r_getuser = mysql_query("SELECT * FROM users WHERE (user_name = BINARY '".mysql_real_escape_string($l_un_em)."' OR email = '".mysql_real_escape_string($l_un_em)."') AND (password = '$md5_pw' OR temp_password = '$md5_pw') AND status >= 0");
if (mysql_num_rows($r_getuser) == 0) {
/* echo $messages['log_un_em_pw_incorrect'];
return; */
$return['return_code'] = -1;
$return['return_msg'] = $messages['log_un_em_pw_incorrect'];
echo json_encode($return);
}
$row = mysql_fetch_assoc($r_getuser);
/* if ($row['privs'] < 1) { echo $messages['log_no_privs']; break; } */
if ($row['temp_password'] == $md5_pw) { //new password
mysql_query("UPDATE users SET password = '".$md5_pw."', temp_password = NULL WHERE user_id = '{$row['user_id']}'");
}
$today = date('Y-m-d');
if ($row['login_0'][0] == '9') { //first login
mysql_query("UPDATE users SET login_0 = '".$today."', login_1 = '".$today."', login_cnt = 1 WHERE user_id = '{$row['user_id']}'");
} else {
mysql_query("UPDATE users SET login_1 = '".$today."', login_cnt = login_cnt+1 WHERE user_id = '{$row['user_id']}'");
}
$_SESSION['uid'] = $row['user_id'];
$_SESSION['unm'] = stripslashes($row['user_name']);
$_SESSION['uml'] = stripslashes($row['email']);
$_SESSION['cL'] = $row['language'];
/* echo '<meta http-equiv="refresh" content="0;url=livemass_CENTER34.php">'; */ //default page
break;
}

$return['return_code'] = 0;
$return['return_msg'] = $messages['log_success'];

echo json_encode($return);
/* return; */
}

echo login_user(trim($_REQUEST['username_email']), trim($_REQUEST['upass']));

?>

最佳答案

在你的 php 文件中使用

 date_default_timezone_set('your time zone');

告诉 php 你的时区是什么。有关详细信息,请参阅 date_default_timezone_set() .

关于带有返回码和返回消息的 PHP 函数,仅供引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10262176/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com