Reputation: 21
We have developed a small application for conducting online exams. We are using CodeIgniters session handling capabilities to manage examinee’s session and it works perfectly fine if the internet connection doesn’t break during the examination. However in India in certain cities the internet connectivity is not that reliable and the internet connection breaks during the exams. At this time although the application stores the exam’s state, we would like to have the user session to expire as soon as there is any loss in internet connectivity.
With codeigniters session handling it compares the session information in client cookie with the one in database and if they match it allows the user to continue in the same session.
Is there a way by which we can create a new session as soon as there is break in internet connection, similar to what we have for banking applications? I’m a novice as far as php & codeigniter is considered, so please pardon if I ask some very basic questions.
Upvotes: 2
Views: 598
Reputation: 5910
Sessions are created and maintained serverside. That means that as soon as your client is not able to connect to the server anymore there is no way to manipulate session information.
With HTML5 a new interface was introduced that is able to take care of your problem. Basically local storage is a key-value storage that persists data. So speaking, it will be available beyond page refreshs.
Now, whenever your application notices that it will not be able to reach the server you need to allocate your data flow to the local storage.
When the server can be reached again, you can send the data from your local storage to the server and check if there were no manipulation attempts on the client side.
In it's most basic form working with the local storage is really simple. You're just setting key/value pairs and you are retrieving the keys.
localStorage.setItem('name', 'thomas'); //Drop something into the local storage
localStorage.getItem('name'); //Retrieve something from the local storage
Of course you need to check for availability of the local storage. Also the implementations differ in various browsers (so the maximum size of data that can be stored can be different for different browsers).
It's really all about allocationg your data flow. So the basic approach would be:
Upvotes: 1