I am working on an Online Quiz.
On every click of the 'next question' button, I have tried the following:
if(isset($_POST['submit']) && isset($_POST['ans']))
{
//process answers and fetch next question
//Increment the Session variable which contains serial of next question
$_SESSION['qnum'] = $_SESSION['qnum']+1;
}
Whenever I click on the F5 button, the session gets updated and a new question is fetched.
The session should be incremented only when the next question button is clicked, otherwise it should not be increment.
The following is what I have tried after referring to an article:
$pageWasRefreshed = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
if($pageWasRefreshed)
{
//refetch the current question.
}
else
{
//refetch the current question and increment the Session Variable
}
- This approach worked fine in Mozilla Firefox
- In IE, both the button click and F5 hits are taken as not refreshed
- In Chrome, both the button click and F5 are taken as refreshed
I have tried some other variations from other articles on StackOverflow and Google, but those didn't work at all including an ajax based solution.