Reputation: 9293
I have a script for counting visitors.
I need to avoid counting my own visit.
if ($ip == "127.0.0.1" or $ip == "31.176.166.1") {return false;}
But I found that my ip address is dynamic.
Is there any way to stop counting my visits in this case?
Upvotes: 1
Views: 123
Reputation: 581
at first get your own ip
$_SERVER['REMOTE_ADDR']
now save it as cookie setcookie("my ip", $_SERVER['REMOTE_ADDR'], strtotime('+10 years'));
if anyone visit your website check that is it matched with your ip then
resturn false
Upvotes: 1
Reputation: 1426
A common way to achieve this is to create a cookie with prolonged expiration for your site in your browser, and do not count the visits from whoever attaches this cookie to the requests. So your if would become something like:
if(isset($_COOKIE['admin']))
return false;
Upvotes: 1
Reputation: 219924
Set a cookie for yourself and then check to see if that cookie exists. If so, don't count yourself.
// on the cookie setting page
setcookie("is_me", 1, strtotime('+10 years'));
// code to check to see if it is you
if ($_COOKIE['is_me']) {return false;}
The easiest way to do this is to create a page only you know about, set the cookie there, and verify it works (and then delete the page if that is the only computer you will use to view your site).
Upvotes: 2