简体   繁体   中英

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM