且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP会话:请解释一下?

更新时间:2023-11-09 23:17:52

好像您没有在main_login.php中使用session_start(),就像提到的etranger一样.您需要在每个新请求的开始处调用该函数才能开始使用会话.

It looks like you're not using session_start() in your main_login.php like etranger alluded to. You need to call that function at the start of each new request to begin using sessions.

否则,如果您调用session_start(),而您只是忽略了在代码示例中显示它,那么在重定向期间会话ID可能会丢失.您是使用基于cookie的会话还是将会话ID作为URL参数传递?尝试在每页顶部打印session_id()SID.这将让您知道会话何时丢失(会话ID会更改或为").

Otherwise, if you are calling session_start() and you just neglected to show it in the code sample, then maybe the session ID is being lost during the redirect. Are you using cookie-based sessions or passing session ID as a URL parameter? Try printing session_id() or SID at the top of each page. This will let you know when the session is lost (the session ID will change or be "").

如果您使用的是基于cookie的会话,则说明cookie可能由于某种原因而丢失.如果您使用URL参数传递会话ID,那么透明会话ID支持可能无法正常工作.

If you're using cookie-based sessions, then maybe the cookie is getting lost for some reason. If you're using URL parameter to pass session ID, then maybe transparent session ID support isn't working right.