[英]setcookie() does not set cookie
I have an internal network running XAMPP.我有一个运行 XAMPP 的内部网络。 I am trying to set a cookie for an item when someone logs in. I use the following code.
当有人登录时,我正在尝试为项目设置 cookie。我使用以下代码。
$Access
will be a 1 if user authenticates correctly.如果用户验证正确,
$Access
将为 1。 When a user enters their username and password it passes to a CheckAuth page with the following code.当用户输入他们的用户名和密码时,它会传递到带有以下代码的 CheckAuth 页面。
$Access = authenticateUser($_POST['Username'],$_POST['Password']);
setcookie("Access", $Access, time()+3600);
header('Location:Newpage.php');
On the NewPage it if I do a $_COOKIE['Access']
it will show me 1 and set everything correctly.在 NewPage 上,如果我执行
$_COOKIE['Access']
它将显示 1 并正确设置所有内容。 If I click a link to another page, say Inventory.php, within the same folder, $_COOKIE['Access']
shows 0 instead of 1.如果我单击另一个页面的链接,例如 Inventory.php,在同一个文件夹中,
$_COOKIE['Access']
显示 0 而不是 1。
What could be the issue that the cookie is magically gone? cookie 神奇地消失了可能是什么问题? I have checked the IE files for the cookie when it is made and it doesn't show up.
我已经检查了 IE 文件中的 cookie 制作时它没有显示出来。
The super global, $_COOKIE
, only contains cookies that were given by the browser to the server in the incoming Request.超级全局
$_COOKIE
仅包含浏览器在传入请求中提供给服务器的 cookies。
setcookie()
only sets up HTTP headers for the outgoing Response that will instruct the browser to set a cookie. setcookie()
只为传出的响应设置 HTTP 标头,该响应将指示浏览器设置 cookie。
If you want this cookie to be available in $_COOKIE
, you'll need to set it manually at the same time as you call set_cookie()
:如果您希望此 cookie 在
$_COOKIE
中可用,则需要在调用set_cookie()
的同时手动设置它:
setcookie('Access', $Access);
$_COOKIE['Access'] = $Access;
$Access = authenticateUser($_POST['Username],$_POST['Password']);
Missing a quote after $_POST['Username $_POST['用户名后缺少引号
$Access = authenticateUser($_POST['Username'],$_POST['Password']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.