PHP +会话数据丢失

发布于 2024-11-17 13:11:26 字数 1001 浏览 0 评论 0原文

我面临着非常奇怪的问题。我有一个基于会话的搜索引擎。

由于未知原因,会话变量在第三页重新加载后丢失。

这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心清如水 2024-11-24 13:11:26

首先,我会检查是否存在到 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 目录中:

# make sure the linux kernel > 2.6.13 and update it if not the case
uname -a
# install inotify
aptitude install inotify-tools
# run inotify in command line just before running your php code
inotifywait -m -r --format '%f : %e' -e modify -e move -e create -e delete /tmp /cookie | while read line;do echo $(date '+%H:%M:%S') ;done;

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 :

# make sure the linux kernel > 2.6.13 and update it if not the case
uname -a
# install inotify
aptitude install inotify-tools
# run inotify in command line just before running your php code
inotifywait -m -r --format '%f : %e' -e modify -e move -e create -e delete /tmp /cookie | while read line;do echo $(date '+%H:%M:%S') ;done;
若相惜即相离 2024-11-24 13:11:26

如果您调用 session_unset('key1') 并且 $_SESSION['key1'] 不存在,您将丢失所有数据
解决方案:

if(isset($_SESSION['key1']){
    session_unset['key1'];
}

if you call session_unset('key1') and $_SESSION['key1'] not exist you lost all data
solution:

if(isset($_SESSION['key1']){
    session_unset['key1'];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文