简体   繁体   English

如果页面在php中刷新,如何会话超时?

[英]How to session timeout if page refresh in php?

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. 我在每个页面上启动了会话,并在设置了相关的会话变量之后,每次刷新页面时或在其他选项卡上浏览相同的URL时,该会话都会被破坏。

You can use session_destroy() to destroy a session. 您可以使用session_destroy()破坏会话。

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 ? 即您的代码的哪几行使用$_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; 只需声明一个会话变量$_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']++; 然后,只需在exam.php页面加载时检查此变量的值是否为0,然后继续加载页面,然后在脚本末尾执行$_SESSION['page_load_count']++; else if value of $_SESSION['page_load_count']>0 then show that the page has been refreshed. 否则,如果$_SESSION['page_load_count']>0表示页面已刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM