[英]Calculate timestamp with php and mysql
I need some assistance with setting up a php script that will redirect a user if their IP and timestamp is older then 20 minutes. 我需要一些帮助来设置一个php脚本,如果用户的IP和时间戳早于20分钟,它将重定向用户。
There may be a better way of doing this. 可能有更好的方法来做到这一点。 I have the page request working and that's dumping the IP Address and Datetime proeprly.
我有页面请求工作,并正在倾向于IP地址和日期时间。 This is what I have pieced together so far with the validation:
这是我到目前为止与验证拼凑在一起的内容:
// 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;
}
Thanks in advance!! 提前致谢!!
Change your where to the following: 将您的位置更改为以下内容:
AND `submitted_time` > CURRENT_TIMESTAMP - INTERVAL 10 MINUTE
No need to use PHP to get the current timestamp. 无需使用PHP来获取当前时间戳。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.