• Hello,

    I have a version of the quiz tool currently live at https://telegraph.co.uk/quiz, which is great. Unfortunately, a large number of people are experiencing the same problem, which goes like this:

    1. person fills in personal details form
    2. click submit
    3. instead of getting the first page of the quiz, they get the “quiz is not enabled” error message.

    This message is coming from includes/site/quiz.php, around line 53 (I’ve made a few changes so I’m not precisely sure). It’s being printed because $_SESSION['wpsqt'][$quizName]['quiz_details']['status'] != 'enabled'. This should have been populated in the first step, when $step is 0.

    If you have any advice about how to debug this, I would really appreciate it!

    Thanks,

    J.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Only thing I can think of is trying logging var_export of $_SESSION['wpsqt'][$quizName]['quiz_details']['status'] to see what value it has.

    Thread Starter jnthnlstr

    (@jnthnlstr)

    Hi!

    I can confirm that $_SESSION['wpsqt'][$quizName] is not set…

    J.

    So $_SESSION['wpsqt'] is set and $quizName is set? But $_SESSION['wpsqt'][$quizName] isn’t?

    Also is your $step == 0 if the same as below (including the if statement below)?

    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 );
    		$_SESSION['wpsqt'][$quizName]['quiz_sections'] = $wpdb->get_results('SELECT * FROM '.WPSQT_SECTION_TABLE.' WHERE quizid = '.$_SESSION['wpsqt'][$quizName]['quiz_details']['id'], ARRAY_A );
    		$_SESSION['wpsqt'][$quizName]['person'] = array();
    		$_SESSION['wpsqt']['start'] = microtime(true);
    	}
    
    	if ( empty($_SESSION['wpsqt'][$quizName]['quiz_details']) && $step !== 0 ){
    		echo 'Error, sessions, failure. Please check your PHP Settings.';
    		return;
    	} elseif (empty($_SESSION['wpsqt'][$quizName]['quiz_details'])) {
    		print 'No such quiz.';
    		return;
    	}
    Thread Starter jnthnlstr

    (@jnthnlstr)

    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;
    	}
    }

    Hey,
    Sorry for the delay, but looking at code and thinking it may be possible that the error is caused by the user not having cookies enabled. The if check that would catch it in your code doesn’t seem to catch it since your doing an if $step == 0 then in that clause checking if $step !== 0.

    I did try the other day to see what error message I would get on that install with no cookies and I got an error happened try again, if you’re logging errors and see an hostname with iain something fubra .com|.net (forgot my hostname in the office) then that will be the issue.

    Thread Starter jnthnlstr

    (@jnthnlstr)

    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.

    This is along shot. The only thing I can think of is, assuming you’re using the file system to store the session data. Mabye there is an error there such as too many read/writes happening so PHP skips it or something. Mabye try using MEMCACHE for sessions.

    To be honest from the randomness sounding of this error, I think it may be a PHP issue. Try logging a var_export of get_defined_vars(). See if anything there is constantly the same.

    Thread Starter jnthnlstr

    (@jnthnlstr)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: WP Survey And Quiz Tool] Quiz sometimes failing after details submission’ is closed to new replies.