jnthnlstr
Forum Replies Created
-
I’m giving that enhanced logging a go. I’ve also added in an extra session var that shows whether the person has encountered an error before, although I’m not sure that will kick in if someone refreshes the page… (not familiar with what causes a new session ID to be assigned).
I believe I am using the filesystem to store sessions. I can’t believe that there is so much traffic that it is causing the system to fail. It’s hard to use apache-bench to simulate simultaneous requests, as the error happens after someone has filled in a form.
I’ll keep you posted about how I get on.
Thanks,
J.
Hi!
Thanks for helping iron this out.
I have seen this error happen on my brother’s computer when I was showing him the quiz – a normal MacBook Air with cookies switched on. I refreshed the page and the error went away.
This transience of the error makes it very difficult for me to debug…
J.
Hi,
Yes, $quizName is set. The missing variable in the session is current_id.
My code is slightly different to what you pasted, as so:
if ( $step == 0 ){ if (isset($_SESSION['wpsqt'][$quizName])) unset($_SESSION['wpsqt'][$quizName]); $_SESSION['wpsqt'][$quizName] = array(); $_SESSION['wpsqt'][$quizName]['start'] = microtime(true); $_SESSION['wpsqt'][$quizName]['quiz_details'] = $wpdb->get_row( $wpdb->prepare('SELECT * FROM '.WPSQT_QUIZ_TABLE.' WHERE name like %s', array($quizName) ), ARRAY_A ); if ( !empty($_SESSION['wpsqt'][$quizName]['quiz_details']) ){ $_SESSION['wpsqt'][$quizName]['quiz_sections'] = $wpdb->get_results('SELECT * FROM '.WPSQT_SECTION_TABLE.' WHERE quizid = '.$_SESSION['wpsqt'][$quizName]['quiz_details']['id'].' ORDER BY id ASC', ARRAY_A ); // JRL: added ORDER BY id ASC so the section order is sensible $_SESSION['wpsqt'][$quizName]['person'] = array(); $_SESSION['wpsqt']['start'] = microtime(true); } elseif ( $step !== 0 ){ echo 'Error, sessions, failure. Please check your PHP Settings.'; return; }else { print 'No such quiz.'; return; } }
Hi!
I can confirm that
$_SESSION['wpsqt'][$quizName]
is not set…J.
Hi,
Good fix.
J.
Looks like this is caused by line 91 in /includes/sitequiz.php:
if ( isset($_POST['answers']) ){ // then the answers and stats arrays are created
Perhaps you could name the submit button and make that what is looked for instead of
$_POST['answers']
?J.
Great stuff!
Hi,
Thanks for the response!
I believe I have tracked down the cause of the problem. I did a test to see what session data was being lost, using an independent session variable, and nothing was being lost, so I looked elsewhere.
It turns out that in /includes/site/quiz.php, line 29, which is:
if ( $step == 0 ){
This if is closed too early, at line 34, whereas it should be closed after line 46. As it stands at the moment, the if statement doesn’t wrap around the statements that refresh thequiz_sections
andperson
variables, hence why I was seeing them deleted from the session data.J.
Another thing I have noticed while poking into this, is that the $_SESSION variable doesn’t preserve the questions and answers for a section into the next section (which is should since they’re not unset); and that the “person” variable ends up blank once you’ve gone past the first page after filling in the personal details form.
So, there is a systematic losing of session data here…