I'm having some strange issues with PHP session variables claiming to not be set. I'm only encountering this in one particular situation:
My site has a 3-step wizard and I use sessions to store the user's selections on each step. To start the wizard, I use an init script that ensures any old wizard session data is wiped out - this init script then redirects the user to step 1. For example:
// Initialize wizard session and send user to step 1
$_SESSION['wizard'] = array();
$_SESSION['wizard']['step1'] = TRUE;
session_write_close();
header('Location: http://mysite.com/wizard/step1.php');
Then at the top of step1.php, I do a check like:
if (!isset($_SESSION['wizard']['step1']))
throw new Exception('Step1 not initialized');
When the user submits the step1 form, it is posted back to itself for validation. If it passes, another redirect is done to step 2.
Most of the time, this works fine. In fact, the init script always works and the step1 form always loads without a problem. But sometimes, after submitting the step 1 form, the 'Step1 not initialized' exception gets thrown. I don't see how the initial load could pass the check but the form post fail it moments later. Especially considering this problem happens infrequently and most of the time there are no problems at all.
I am using a database to store my session data and I don't think this is due to session timeouts or garbage collection - some related php.ini values:
session.use_cookies = 1
session.cookie_lifetime = 0
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 86400
Does anyone know what could be causing such a problem? Any insight would be greatly appreciated.
Thanks, Brian