2

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?

4
  • I'd say that if sessions work twice, your settings are fine. Have you considered reviewing your code? Commented Jun 27, 2011 at 20:01
  • 2
    The only reason I could think of, is that you did not start the session. Try using var_dump or print_r your session variables, and see where they get lost. Recently, I just faced something like this and sure enough I did not start my session. Commented Jun 27, 2011 at 20:02
  • aside php.ini setup, you shall make sure you started the sesison in your code (eg session_start() at the very beginning of your php page, but I guess this is done). Are you redirecting from http to https when reloading the page - as this is a case of session loss ? Commented Jun 27, 2011 at 21:26
  • @hornetbzz Session is started correctly. It's simple script with pagination. Have no idea what's going on. Commented Jun 27, 2011 at 21:30

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.