Jump to content

Help ending a PHP session when a page is closed


edd12345678

Recommended Posts

Hi Everyone,

 

I wonder if somebody could help me. I have been at this for hours and am really struggling.

 

I have a timer which I have set up for a quiz.  The quiz opens in a javascript shadow box.  When the quiz is opened a session variable for the timer is set up to keep track of the time. 

 

What I need is for this session variable to end when the shadow box is closed. I have a onClose hook to peform actions when the shadow box is closed which is in javascript.

 

Obviously I cannot end the session variable in the javascript function due to js being client side and php being server side.

 

Has anyone any suggestions how I can resolve this issue.

 

I need to end this session variable as if the user exits the quiz and then selects another quiz to do the timer uses the current time session rather than assigning the new time value for that particular quiz.

 

Thanks in advance. 

 

Edd

Link to comment
Share on other sites

Starting/ending sessions is not what you should be doing here.  A session exists to stitch together requests from the same client over a period of time.  Trying to force it to become a timer is not how you should approach this problem.

 

Instead, use one or more session variables.  For example:

 

$_SESSION['currentQuizId'] = $currentQuizId;
$_SESSION['quizStarted'] = date;

 

kicken provided one of the best methods for making the page interactive -- using ajax calls to synchronize your quiz app with the backend.

 

 

Link to comment
Share on other sites

Hi,

 

Thankyou for yoru replies.

 

I do have more than one session variable in the quiz to handle other aspects of it but just really need to end the time variable although I guess I could end all of them to kill the timer.

 

I have never used ajax calls before. Are they difficult? Is it possible to provide an example of how to end a session variable using one?

 

Thanks again and apologies for my naivity .

 

Edd

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.