i am making a 10 question survey with one question at a point. i made a session for passing values between questions. the thing i discovered is that the session values do not get destroyed even on a page refresh. is there a workaround or am i doing something wrong.
just to make things clear, here is the code:
session_start();
// $_SESSION['score'] = $score;
$_SESSION['qnum'] = isset($_SESSION['qnum']) ? $_SESSION['qnum']+1 : 1;
if ($_SESSION['qnum'] < 10){
$_SESSION['total'] = isset($_SESSION['total']) ? $_SESSION['total']+$score : $score;
}
else if ($_SESSION['qnum'] == 10){
$_SESSION['total'] = isset($_SESSION['total']) ? $_SESSION['total']+$score : $score;
echo "finished";
}
echo $_SESSION['qnum'];
echo '\n';
echo $_SESSION['total'];
$_SESSION variables will remain until you terminate the session or unset() the session variable.
To end a session try this code:
To delete a session variable use: