简体   繁体   中英

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 sessions.

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 ie log-in --> log-out ?

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

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,...).

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.

除非您将会话存储在数据库中并在每次用户登录时重新填充$ _SESSION,否则它们不会在计算机之间跟踪您。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM