开发者

PHP session not storing data

HI ,

Say if I am viewing my page on computer 001 and I logout of the session and move onto computer 002 and log-in into the session for some reason I don't see my data it looks like its something to do with how I have done my sess开发者_高级运维ions.

does any one know why the data is not saving to the user ?

And how I could fix it ?


You've log-out... isn't a session's scope bound to the lifetime of the session i.e. log-in --> log-out ?

You need persistent state: use a database. But don't confuse persistent state with transient session ;-)


From the PHP docs: "A visitor accessing your web site is assigned a unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL."

When you log out, that cookie is expired.

Even if you don't log out, destroying the cookie, when you move to a second computer, the cookie doesn't follow you. So PHP has no way of linking the new session with the old session. If you need to link what you're calling a "session" (as opposed to the PHP $_SESSION), then you'll need to store all of that data somewhere yourself. PHP won't do it for you.

You can write out the $_SESSION variables to a database when the user logs out if you have an explicit logout function. If you need a user to be able to just wander away and resume later without having explicitly logged out, then you'll probably need to save all of that information on each page the user accesses.


The data are saved per session, when you log out, you destroy the session and all associated data. You have to store it yourself (database, files,...).


Unless you store sessions in a database and re-populate $_SESSION every time a user logs in, they aren't going to follow you from computer to computer.


That's pretty much it, sessions wont' carry over from different IP sources. They also expire after a certain amount of time. If you want to carry data over from login/logout procedures you'll need to store it in the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜