gpt4 book ai didi

php - 使用php和mysql计算时间戳

转载 作者:行者123 更新时间:2023-11-29 08:18:07 24 4
gpt4 key购买 nike

我需要一些帮助来设置一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com