简体   繁体   English

用户更改IP时,PHP会话Cookie失败

[英]PHP Session Cookies fail with users changing IP

I have a login script for a small application that works by storing session cookies and checking them on each page to make sure the user is logged in. One of the two users who uses the system keeps getting logged out randomly. 我有一个小应用程序的登录脚本,它通过存储会话cookie并在每个页面上检查它们来确保用户已登录。使用该系统的两个用户中的一个不断随机登出。 This appears to be down to the session cookie that shows then authenticated no longer being present. 这似乎是会话cookie,显示经过身份验证后不再存在。

After a lot of investigation the only thing I can see that is different about this user is that their IP address is changing (today it was changing every hour (their on Sky)). 经过大量调查后,我能看到的唯一不同的是,这个用户的IP地址正在发生变化(今天它每小时都在变化(他们在Sky上))。 The only thing is the change of IP address has happened 5 times this morning and only once has the user been logged off. 唯一的问题是IP地址的变化今天早上发生了5次,只有一次用户已经注销。

Has anyone had a similar issue? 有没有人有类似的问题?

Are session cookies in someway tied to IP addresses? 会话cookie是否与IP地址绑定?

Any help or links much appreciated. 任何帮助或链接非常感谢。

Thanks 谢谢

C C

Are session cookies in someway tied to IP addresses? 会话cookie是否与IP地址绑定?

No. As long as the browser is connecting to the same IP name serverside it doesn't matter if the clients address changes or goes via a different proxy. 不可以。只要浏览器连接到相同的IP名称服务器端,无论客户端是通过其他代理进行更改还是通过其他代理进行更改都无关紧要。

It's more likely that something is getting cached where it shouldn't. 更有可能的是某些东西被缓存到它不应该的地方。 (assuming you are doing no validation against IP address). (假设您没有对IP地址进行验证)。

Have you got your webserver configured to log session ids against the request/client/user agent? 您是否已将Web服务器配置为针对请求/客户端/用户代理记录会话ID? (ie in the access log) (即在访问日志中)

C. C。

By default the PHP Session does not account for IP changes. 默认情况下,PHP会话不考虑IP更改。 It's only based in the cookie value. 它仅基于cookie值。

So perhaps maybe there is some customized code in your web app that invalidates the session when a user changes the IP address. 因此,也许在您的Web应用程序中有一些自定义代码会在用户更改IP地址时使会话无效。

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

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