强制请求中的会话 ID
有谁知道为什么这行不通?
if(isset($_POST['PHPSESSID'])) {
session_id($_POST['PHPSESSID']);
session_start();
var_dump($_SESSION);
}
var_dump($_SESSION);总是空的!应该是装满东西的吧!是否有任何设置可以防止强制使用会话 ID?自动启动未启用。
Does anyone have any thoughts about why this wouldn't work?
if(isset($_POST['PHPSESSID'])) {
session_id($_POST['PHPSESSID']);
session_start();
var_dump($_SESSION);
}
The var_dump($_SESSION); is always empty! It should be loaded with stuff! Are there any settings that prevent forcing session IDs? Auto start is not enabled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您发布的代码是正确的。但是,由于以下几个原因之一,您可能在会话中看不到变量:
$_POST['PHPSESSID']
未设置$_POST['PHPSESSID']
包含非- 数字字符$_POST['PHPSESSID']
不是指session_id
之前调用填充的会话 IDsession_start()
如果这些都不适用,我不知道问题是什么,但你为什么不尝试使用
session_name()
(它是为你想要做的事情而设计的)而不是session_id
?The code you posted is correct. However, you may not be seeing variables in your session for one of several reasons:
$_POST['PHPSESSID']
is not set$_POST['PHPSESSID']
contains non-numeric characters$_POST['PHPSESSID']
does not refer to a populated session IDsession_start()
was called before your call tosession_id
If none of these apply, I don't know what the issue is, but why don't you try using
session_name()
(which was designed for what you're trying to do) instead ofsession_id
?您的
$_POST['PHPSESSID']
一定是错误的:检查其值。如果更改了会话处理程序,则必须仅使用该特定会话处理程序允许的字符。
资源:
Your
$_POST['PHPSESSID']
must be wrong :Check its value. If you changed the session handler, you must use only the allowed characters for this specific session handler.
Resources :
会话保存路径存在问题。它设置不正确,所以我可以猜测 PHP 依赖浏览器 cookie 来创建会话,而不是会话保存路径中的文件。
There was an issue with the session save path. It wasn't set up right, so I can guess that PHP was relying on browser cookies to create the session instead of the files in the session save path.