如何从具有不同 URL 的网页访问 cookie 信息
How to access cookie information from a webpage with a different URL
我的代码设置了一个cookie,如下所示;我无法从具有不同 URL 的页面获取 cookie 信息...我的代码有问题吗?如果您有任何问题,请告诉我。
zzz.php;
setcookie ("mail", $mail, time()+3600*24*365*10);
setcookie ("name", $name, time()+3600*24*365*10);
setcookie ("password", $password, time()+3600*24*365*10);
.....
http_response_code(301);
header("Location: ../xxx.php");
xxx.php;
echo $_COOKIE['mail'];
在 xxx.php 上,没有出现。
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
如果您希望 cookie 在父目录中可用,则需要设置 cookie 的路径。最简单的方法是将所有 cookie 设置为路径 /
,这样 cookie 在该域的任何地方都可用:
setcookie ("mail", $mail, time()+3600*24*365*10, '/');
setcookie ("name", $name, time()+3600*24*365*10, '/');
setcookie ("password", $password, time()+3600*24*365*10, '/');
我的代码设置了一个cookie,如下所示;我无法从具有不同 URL 的页面获取 cookie 信息...我的代码有问题吗?如果您有任何问题,请告诉我。
zzz.php;
setcookie ("mail", $mail, time()+3600*24*365*10);
setcookie ("name", $name, time()+3600*24*365*10);
setcookie ("password", $password, time()+3600*24*365*10);
.....
http_response_code(301);
header("Location: ../xxx.php");
xxx.php;
echo $_COOKIE['mail'];
在 xxx.php 上,没有出现。
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
如果您希望 cookie 在父目录中可用,则需要设置 cookie 的路径。最简单的方法是将所有 cookie 设置为路径 /
,这样 cookie 在该域的任何地方都可用:
setcookie ("mail", $mail, time()+3600*24*365*10, '/');
setcookie ("name", $name, time()+3600*24*365*10, '/');
setcookie ("password", $password, time()+3600*24*365*10, '/');