gpt4 book ai didi

php - 某些浏览器中 cookie 的未定义索引

转载 作者:行者123 更新时间:2023-11-29 13:36:01 25 4
gpt4 key购买 nike

我正在使用我在专家交换中找到的登录脚本来在用户登录时制作 cookie。

登录页面是这样处理的:

function process_login() {

var username = $.trim($('#input_username').val());
var password = $.trim($('#input_password').val());

username = $.trim(username);
password = $.trim(password);
var remember = document.getElementById("remember_user_checkbox").checked;

if (!username || !password) {

return false;

}

remember == true ? remember = "true" : remember = "false";

$.ajax({
type: "POST",
cache: false,
url: "login_user.php",
data: "username=" + username + "&password=" + password + "&remember=" + remember,
dataType: "json",
success: function (data) {

if (data == "FALSE") {

$('#input_password').val("");

alert("The username or password you have entered is incorrect.");

return false;
}

window.location = "orders-home.php?<?=time()?>";

}

});

}

并提交到login-user.php,在这里:

<?php
include('login-config.php');
$username = pg_escape_string($_POST['username']);
$password = pg_escape_string($_POST['password']);

//no encryption for now


//php gets this as a string
$remember = $_POST['remember'];

if ( $remember == "true" )
{
$remember = TRUE;
}
else
{
$remember = FALSE;
}


$user_query = "SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1";

$user_result = pg_query( $con , $user_query );

if ( !$user_result )
{
echo json_encode("FALSE");
}


$arr = array();

if (!$user_result)
{
die( pg_last_error($con) );
}
else
{

while ( $row = pg_fetch_array($user_result) )
{

//put the customer id in a session so we can put it in a cookie later
//then when the page is refreshed the stored customer id will be used
//as their ksisoldby identifier
if ( $row['cust_id'] )
{
$_SESSION['customer_id'] = $row['cust_id'];
$_SESSION['customer_name'] = $row['first_name']." ".$row['last_name'];
$_SESSION['uid'] = $row['id'];


if ( $remember )
{
remember_user($row["id"]);
}
}

$arr[] = array(

"first_name" =>$row['first_name'],
"last_name" =>$row['last_name'],
"customer_id" =>$row['cust_id'],
"accepted_terms" =>$row['accepted_terms'],
);
}

}

if ( empty($arr) ){
echo json_encode('FALSE');
}
else
{

$path = '/webtrack';
$site = 'www.isco.net';


if ($remember === TRUE)
{
$remember_time = time()+60*60*24*30;

setcookie('username', $username, $remember_time, $path, $site);
setcookie('customer_id', $_SESSION['customer_id'], $remember_time, $path, $site);
setcookie('customer_name', $_SESSION['customer_name'], $remember_time, $path, $site);
// setcookie('uuk', $uuk, $remember_time, $path, $site);

}
else
{
setcookie('username', $username, false, $path, $site);
setcookie('customer_id', $_SESSION['customer_id'], false, $path, $site);
setcookie('customer_name', $_SESSION['customer_name'], false, $path, $site);

}

echo json_encode($arr);

}
?>

然后我从那个 cookie 打印到主屏幕上

<div class="fl customer_id">
<?= strtoupper($_COOKIE['customer_name']); ?>
</div>

但是我得到了错误

注意:未定义索引:/home/iscotest/public_html/webtrack/orders-home.php 中的 customer_name

实际站点是 www.isco.net。但该网站托管在 iscotest.com。 isco.net 只是指向 iscotest.com。这可能是我的 cookie 没有被设置的原因吗?

这是一个很大的问题,因为这完全停止了页面加载,因为该 cookie 信息用于检索显示的数据

另一件奇怪的事情是这个错误并没有一直出现。我在一台计算机上的 safari 和 chrome 上出现错误,但该站点在另一台计算机上的 safari 和 chrome 中正常运行。

感谢您的帮助

最佳答案

当您使用 setcookie() 创建一个 COOKIE 时,这将仅在另一个页面上可用。因此,这可能是您的 AJAX 问题。

关于php - 某些浏览器中 cookie 的未定义索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11506833/

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