Reputation: 11
I am developing a exam application and I want that when user give exam than on that time no one can reload my page.
I want to destroy session if my page refresh. I started the session on each page and after relevant session variables are set, the session is destroyed each time the page is refreshed or when I browse the same URL on a different tab.
Upvotes: 1
Views: 1914
Reputation: 126
I was also stuck in same kind of problem.
Just declare a session variable $_SESSION['page_load_count'] = 0;
while creating/setting session after authentication.
Then just check this variable on exam.php page load if the value is 0 then continue loading the page and at the end of script just do a $_SESSION['page_load_count']++;
else if value of $_SESSION['page_load_count']>0
then show that the page has been refreshed.
Upvotes: 0
Reputation: 6406
You can use session_destroy()
to destroy a session.
However the whole point of sessions is to persist data between page refreshes; if you want to destroy this data each refresh it would be easier not to use a session.
What are you storing in the session; this might make a solution to your problem clearer? I.e. what lines of your code use $_SESSION
? Please post some. Maybe it's an external library that taps into the session?
Upvotes: 2