I want to check if a device's IP has been stored before, if so, check if IP storage time and now() is greater than 10min and do stuff.
here's my PHP to cheeck if IP is present in the database.
$ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$query = "SELECT * FROM messages WHERE ip = '$ip'";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
echo "IP Present..";
}
I have a column in the database named messageTime which stores the time when an IP gets stored.
You can do it directly in mysql like below:
$query = "SELECT * FROM messages WHERE ip = '$ip' AND date_sub(now(), INTERVAL 10 MINUTE) = now()";
Try the following query:
$query = "SELECT * FROM messages WHERE ip = '$ip' AND messageTime >= '".strtotime('-10 minutes')."'";
This will select all rows where ip is the users IP and where the messageTime is newer than now -10 minutes. This will only work if your messageTime is a unix timestamp