1

I've encountered this error with session in PHP: sometimes (after 30-40 page refreshes and very rarely after just 1 page refresh) the session variable (filled in the previous page properly - I've checked it that it's set) is empty like: array(0){ }, but the file of that session that is accessed contains desired content and it takes one more page refresh to load that session data (yes, I've checked that session ids are realy the same on both pages). Does anyone know why is it happening? What to do to avoid this "empty array blink"?

To clarify what I'm doing: on the main page I'm saving CSS string into a session variable and generating a link tag pointing to a PHP script. This script when called by broswer loads that CSS string from a session and outputs it as a CSS file. So, it's actualy only the main page that is being refreshed.

This "empty array blink" also appears when I successfully load the page and than load some other website in a different broswer tab, than I go back to a tab with my page and refreshes it, the the session error I'm talking about appears (and disapears after next refresh of my page the way I've described above); but again it's not the rule, it happens only sometimes.

Please consider the following:

  • Yes, the session_start(); is in the beginning of files

  • I use pure PHP session mechanism (with simple aplication logic: only saving a string under the session variable and retrieving it on the next page)

  • I use local server (MAMP), so no accidental deletion in /temp folder by scripts of others

  • I tried to set up: session.gc_probability = 1, session.gc_divisor = 100 and session.gc_maxlifetime = 1440, but it didn't help; different session's lifetimes didn't help as well and I also tried: session.use_cookies = 1 with session.use_only_cookies = 1
  • Yes, it realy looks like something is going on when the session_start(); is called and the garbage collector tries do it's job, but why the same session file with the exactly the same session id is used than when one more (the successful one) refresh is performed?
  • I found something very similar being described here as:

    • So my guess is that after the session expires on the server, the browser still has the PHPSESSID cookie. If it sends that to the server, the server can't find the session and just puts an empty array in $_SESSION, leaving me clueless. I hope this helps somebody having the same problem.

Michal
  • 43
  • 8
  • Possible duplicate of [PHP sessions default timeout](https://stackoverflow.com/questions/9904105/php-sessions-default-timeout) – Anwar Jul 13 '17 at 10:22
  • No, `session.gc_maxlifetime = 1440` unfortunately didn't help. – Michal Jul 13 '17 at 10:30

0 Answers0