Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP: outsync or concurrent session variable arrays inside session
    text
    copied!<p>I'm having a really wierd problem with PHP session variables. Based on the session ID it looks like there would be double variables inside same session which naturally cannot be possible.</p> <p>The problem is that 'quote' session variable should remain same when form in page is submitted which reloads the page itself. The $_SESSION['quote'] variable is set only if it's not defined, what happens in first two reloads as can be seen logs below. </p> <p>Debug code:</p> <pre><code>echo "\n Current session id: ".session_id(); echo "\n _SESSION['quote']: ".$_SESSION['quote']; $_SESSION['counter'] = isset($_SESSION['counter'])? $_SESSION['counter'] +1 : 0; echo "\n _SESSION['counter']: ".$_SESSION['counter']; Output when page is reloaded(form submitted): Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: ; $_SESSION['counter']: 0; set _SESSION['quote']: 984; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: ; $_SESSION['counter']: 0; set _SESSION['quote']: 985; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: 985; $_SESSION['counter']: 1; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: 985; $_SESSION['counter']: 2; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: 984; $_SESSION['counter']: 1; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: 985; $_SESSION['counter']: 3; Current session id: r5i15u4s9e20ud4j6jke8ln376; $_SESSION['quote']: 984; $_SESSION['counter']: 2; </code></pre> <p>This problem happens with Firefox and IE. Any advice or tip would be highly appreciated. Thanks in advance.</p> <p>---EDIT--- Added echo serialize($_SESSION); as proposed.</p> <pre><code>&lt;?php session_start(); echo "\nSerialized data at begin of page: "; echo serialize($_SESSION); echo "\n Current session id: ".session_id(); echo "\n _SESSION['quote']: ".$_SESSION['quote']; $_SESSION['counter'] = isset($_SESSION['counter'])? $_SESSION['counter'] +1 : 0; echo "\n _SESSION['counter']: ".$_SESSION['counter']; </code></pre> <p>OUTPUT:</p> <pre><code>Initial loading of page: Serialized data at begin of page: a:0:{} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: $_SESSION['counter']: 0 ... Serialized data at end of page: a:1:{s:7:"counter";i:0;} Page 1. reload by form submit: Serialized data at begin of page: a:0:{} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: $_SESSION['counter']: 0 ... Serialized data at end of page: a:3:{s:7:"counter";i:0;s:8:"quote";i:1023;s:9:"quotedate";s:10:"2010-11-18";} Page 2. reload by form submit: Serialized data at begin of page: a:1:{s:7:"counter";i:0;} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: $_SESSION['counter']: 1 ... Serialized data at end of page: a:3:{s:7:"counter";i:1;s:8:"quote";i:1024;s:9:"quotedate";s:10:"2010-11-18";} Page 3. reload by form submit: Serialized data at begin of page: a:3:{s:7:"counter";i:0;s:8:"quote";i:1023;s:9:"quotedate";s:10:"2010-11-18";} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: 1023 $_SESSION['counter']: 1 ... Serialized data at end of page: a:3:{s:7:"counter";i:1;s:8:"quote";i:1023;s:9:"quotedate";s:10:"2010-11-18";} Page 4. reload by form submit: Serialized data at begin of page: a:3:{s:7:"counter";i:1;s:8:"quote";i:1024;s:9:"quotedate";s:10:"2010-11-18";} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: 1024 $_SESSION['counter']: 2 ... Serialized data at end of page: a:3:{s:7:"counter";i:2;s:8:"quote";i:1024;s:9:"quotedate";s:10:"2010-11-18";} Page 5. reload by form submit: Serialized data at begin of page: a:3:{s:7:"counter";i:1;s:8:"quote";i:1023;s:9:"quotedate";s:10:"2010-11-18";} Current session id: vbbpohof2jo757eaj5jrp4dv02 $_SESSION['quote']: 1023 $_SESSION['counter']: 2 ... Serialized data at end of page: a:3:{s:7:"counter";i:2;s:8:"quote";i:1023;s:9:"quotedate";s:10:"2010-11-18";} </code></pre> <p>I hope this demonstrates my problem better than unclear original description. Sorry for that. This time "two concurrent" session variable arrays, if such can be, seem to be active one after another. Sometimes other is active few times and then another...</p> <p>---EDIT---</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload