PHP +会话数据丢失
我面临着非常奇怪的问题。我有一个基于会话的搜索引擎。
由于未知原因,会话变量在第三页重新加载后丢失。
这是 PHP 配置:
session.auto_start On Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 0
session.hash_bits_per_character 5 4
session.hash_function 1 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php5 /var/lib/php5
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On Off
session.use_trans_sid 0 0
您对如何调试这个问题有什么想法吗?
I'm facing really weird issue. I have a search engine, session based.
For unknown reason, session variables are lost after third page reloading.
Here's PHP configuration:
session.auto_start On Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 0
session.hash_bits_per_character 5 4
session.hash_function 1 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php5 /var/lib/php5
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On Off
session.use_trans_sid 0 0
Do you have any ideas how to debug this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我会检查是否存在到 https 的重定向,因为这是 会话丢失。
我会确保在重定向后有一个 exit(); 。
我还会尝试在 php.ini 中关闭 * session.auto_start * 并在代码中启动会话,并将该会话 cookie 放入 /tmp 目录 i/o /var/lib/php5。
然后,我首先使用简单的 var 转储 查看各个代码点的 $_SESSION 数据。
最后,您可以使用 inotify 结合 2 个文件研究来跟踪会话文件更改:一个查看会话 cookie,另一个在您的 php 代码中设置,以便您可以并排检查两个文件。
对于 debian 发行版,假设您在 php 代码中的战略点的 /cookie 目录中创建了一个临时文件,并且您的会话 cookie 存储在 tmp 目录中:
At first I would check whether there is a redirection to https as this is a case of session loss.
I would make sure to have an exit(); after the redirection.
I would also try to turn off * session.auto_start * in the php.ini and start the session within the code, and put that session cookie into the /tmp directory i/o /var/lib/php5.
Then I would first look at the $_SESSION data at various code points with a simple var dump.
And finally, you could track the session file changes using inotify combinining 2 files researches: one looking at the session cookie, and the other one set up within your php code, sothat you can check both side by side.
For a debian distro, assuming you create a temp file in the directory /cookie within your php code at strategic point(s) and your session cookie is strored in your tmp directory :
如果您调用
session_unset('key1')
并且$_SESSION['key1']
不存在,您将丢失所有数据解决方案:
if you call
session_unset('key1')
and$_SESSION['key1']
not exist you lost all datasolution: