But the user can delete the cookie! That is hardly secure for an examination.
The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.
Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.
The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.
The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.
Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.
The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.
How will you know that they have deleted the cookie? A new cookie and new session id will be generated.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please
If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.
What do you want to stop from happening if the user refreshes the web page?
If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.
What do you want to stop from happening if the user refreshes the web page?
See post#2. Re-starting the timer, of course.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
How will you know that they have deleted the cookie? A new cookie and new session id will be generated.
You would then have two entries on the server with the same name attached - one for each of the cookies.
You just need it set up so that the server side data the cookie refers to doesn't get deleted until after the exam has been marked. Deleting the cookie would just remove the person's ability to complete that particular exam.