![](/img/trans.png)
[英]How can I delay the execution time of a php script, so the python script can finish
[英]Delay time til user can run a php script again
我搜索了很多内容,却没有找到简单的答案,我所需要的就是不要让用户过快地运行相同的php脚本,就像他发送表格一样,我需要阻止相同的表格才能再次运行10秒
我尝试使用:
if(isset($_SESSION['var']){
exit;
}
并在脚本开始处设置var,然后在脚本完成时将其取消设置,但这只会禁止他在当前正在运行的脚本上运行,有什么办法吗?
您可以使用超时来防止用户运行脚本快速运行,但是php使用Session来存储超时,如下所示:
session_start(); //At the beginning of the PHP file
define("TIMEOUT", 10); //10 sec
//Check timeout
if (isset($_SESSION['expire'])) {
if ($_SESSION['expire']-time()>TIMEOUT) {
unset($_SESSION['expire']);
}
}
//Allow to do submit after 10 sec
if (!isset($_SESSION['expire'])) {
$_SESSION['expire']=time();
//Your submit code
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.