Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore old session when user accidentally closes the browser?

Tags:

php

I am planning to create a online examination sytem in PHP. What steps could I take to restore old session, if user has accidentally closed the window?

Suppose he has already answered 49 questions out of 50 and suddenly there is power cut off (and there is no UPS) or he accidentally closes the window (even by mistake, if he clicks yes on javascript's prompt on window.unload event) and then reopens the browser, everything is lost. What could I possibly do to prevent this?

Thanks in advance :)

like image 602
TCM Avatar asked Dec 16 '22 23:12

TCM


1 Answers

You would need to do one of two things:

  1. Persist the current state on the user machine - this would have to be done via a cookie.

  2. Persist the current state on the server.

The second option is probably more reliable, it does require that you are in constant contact with the server. It would also allow the session to resume on another machine.

The first option would probably be easier to implement.

like image 64
ChrisF Avatar answered Mar 09 '23 00:03

ChrisF