My system is continuously recording data without control from it ip
.
How can I make it so that ip
it does not register data again, unless 48 hours have passed for it to register again?
I understand that from a previous query, the last inserted data must be obtained:
SELECT visitor_ip FROM visitors_table ORDER BY visitor_date DESC LIMIT 1
But how do I validate it, if the 48 hours have not yet passed that you do not insert data and if the 48 hours have already passed, your data must be re-registered.
<?php
require_once('visitors_connections.php');
$visitor_ip = GetIP();
$visitor_browser = getBrowserType($_SERVER['HTTP_USER_AGENT']);
$visitor_date = date("Y-m-d H:i:s");
$visitor_refferer = $refferer;
$visited_page = selfURL();
$stmt = $con->prepare("INSERT INTO visitors_table (visitor_ip, visitor_browser, visitor_date,
visitor_refferer, visitor_page) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $visitor_ip,$visitor_browser,$visitor_date,$visitor_refferer,$visited_page);
$stmt->execute();
?>
You can make the query if it exists by limiting the dates to the last 48 hours, for example:
Take into account that the same IP can have several connected devices (routers) so it would be more convenient to also filter by user agent or visitor_browser
That would count the visits of a chrome but not of an ipad for example. If this query does not give results, you proceed to make the insert.
Side note, IPs should be stored in a varchar of at least 45 letters to support IPv6
For example, the facebook externalhit that generates the thumbnails and the summary of a link shared on the social network would look something like this (IP, date, UserAgent):
Also another user agent that could be misleading is that of CloudFlare
All together would be:
I understand try it like this:
I leave you the Link where maybe it will help you a little more to understand
I hope it works for you and you mark it xD... ReNiceCode...
If you are based on the visit of a user you can make a select first to see which is the last registered field for example
and save the result in a PHP variable
then compare it with the current one
I hope you find it useful
Record the same
ip
after48hrs
it is equal to2 días
.For this we can play through
presente
andfuturo
.Examples:
Then you perform the check using a
if
Once you have the idea in mind you can perform the following procedure: