我想要消除 GOTO 指令(因为你知道只支持最新版本的php)才能使我的代码更兼容,但我真的无法弄清楚如何改变没有 GOTO 的代码流程(不重复代码)。谢谢你的帮助。
答案 0 :(得分:5)
<?php
include("/LIB/error.php");
session_start();
if (isset($_POST['Submit1'])) {
// if 'token' isn't in SESSION then it jumps right away to where dale: was
// otherwise it performs the check and if that fails it does dale: again
if (isset($_SESSION['token']) && (time() - $_SESSION['token']) < 5) {
error('Debes esperar 5 segundos para poder enviar otra informacion.');
} else {
$_SESSION['token'] = time();
include("/LIB/HeadSQL.php");
include("/LIB/comprueba.php");
}
}
?>
答案 1 :(得分:0)
重新排序if / else块(然后当然会改变时间条件)并且变得容易。
<?php
include("/LIB/error.php");
session_start();
if (isset($_POST['Submit1'])) {
if (!isset($_SESSION['token']) || (time() - $_SESSION['token']) >= 5) {
$_SESSION['token'] = time();
include("/LIB/HeadSQL.php");
include("/LIB/comprueba.php");
}
else {
error('Debes esperar 5 segundos para poder enviar otra informacion.');
}
}
?>