我需要一些帮助来设置一个 php 脚本,如果用户的 IP 和时间戳早于 20 分钟,该脚本将重定向用户。
可能有更好的方法来做到这一点。我的页面请求正在运行,并且正在正确转储 IP 地址和日期时间。这是我迄今为止通过验证拼凑出来的内容:
// Check IP address and Time Stamp and block access if needed
$query = "SELECT count(`id`) AS 'count'
FROM `visits`
WHERE
`client_ip` = '".mysqli_real_escape_string($_SERVER['REMOTE_ADDR'])."'
AND `submitted_time` > '".date('Y-m-d H:i:s',strtotime('-10 minutes'))."'
LIMIT 1";
$result = mysqli_fetch_assoc(mysqli_query($query));
if ($result['count'] > 0) {
echo "You have already submitted within the last hour";}
else
{
header("Location: control/index1.php");
exit;
}
提前致谢!!
最佳答案
将您的位置更改为以下内容:
AND `submitted_time` > CURRENT_TIMESTAMP - INTERVAL 10 MINUTE
无需使用 PHP 来获取当前时间戳。
关于php - 使用php和mysql计算时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20152752/