I’ve simple script that store time/IP/PATH just how many online visitors script
$timeoutseconds= 50;
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
it will insert the following informations for any visitor time $timestamp IP $REMOTE_ADDR and Main Path $PHP_SELF
$sql= "insert into online VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')";
executeupdate($sql);
it will delete only if timestamp<$timeout
$sql= "delete from online WHERE timestamp<$timeout";
executeupdate($sql);
But this means if someone start making Zillions of reload for the page before $timeout ends will be counted over and over and over again !
so how can i modify it so that it depends on IP $REMOTE_ADDR and does not insert it if exist in order to repent repeating for same visitor since i’m willing to put it in footer which is in all pages of my website ! ~ thanks
Assuming you’re using MySQL, make the ip field the primary key, and use this query:
(This is assuming the following column names:
ip,timestamp,page)By the way, you should protect against SQL injection, if you aren’t doing so already. Don’t insert external data verbatim in your database. But use proper escaping mechanisms; preferably parameterized prepared statements. This can be done with PDO for instance.