开发者

PHP + Session data being lost

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开发者_C百科   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?


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;


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜