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.
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? Ie what lines of your code use $_SESSION
? Please post some. Maybe it's an external library that taps into the session?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.