edd12345678 Posted February 4, 2012 Share Posted February 4, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256390-help-ending-a-php-session-when-a-page-is-closed/ Share on other sites More sharing options...
kicken Posted February 4, 2012 Share Posted February 4, 2012 Kick off an XHR request to a php script on the server when the box is closed which will mark the end time. Quote Link to comment https://forums.phpfreaks.com/topic/256390-help-ending-a-php-session-when-a-page-is-closed/#findComment-1314464 Share on other sites More sharing options...
gizmola Posted February 4, 2012 Share Posted February 4, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256390-help-ending-a-php-session-when-a-page-is-closed/#findComment-1314467 Share on other sites More sharing options...
edd12345678 Posted February 4, 2012 Author Share Posted February 4, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256390-help-ending-a-php-session-when-a-page-is-closed/#findComment-1314470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.