简体   繁体   English

PHP会话不存储数据

[英]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. 假设我在计算机001上查看我的页面,并且退出会话并移至计算机002并由于某种原因登录到该会话,但我看不到我的数据,这似乎与我的工作方式有关我的会议。

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." 从PHP文档中:“访问您的网站的访问者被分配了一个唯一的ID,即所谓的会话ID。它要么存储在用户端的Cookie中,要么在URL中传播。”

When you log out, that cookie is expired. 当您注销时,该cookie已过期。

Even if you don't log out, destroying the cookie, when you move to a second computer, the cookie doesn't follow you. 即使您没有注销,也破坏了cookie,但是当您移动到第二台计算机时,cookie也不会跟随您。 So PHP has no way of linking the new session with the old session. 因此,PHP无法将新会话与旧会话链接。 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 $ _SESSION相反),则需要将所有这些数据存储在自己的某个位置。 PHP won't do it for you. PHP不会为您做到这一点。

You can write out the $_SESSION variables to a database when the user logs out if you have an explicit logout function. 如果您具有显式注销功能,则可以在用户注销时将$ _SESSION变量写出到数据库中。 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. 就是这样,会话不会从不同的IP来源继续进行。 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. 如果要从登录/注销过程中继承数据,则需要将其存储在数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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