SN1P3R_85 Posted September 1, 2008 Share Posted September 1, 2008 I made a very simple ip logger for my website, It just records the ip of everyone who connects to my main page, and then records the date and time. I visit my site so often, that 90% of the ip's in the ip log are mine. I want to exclude my ip from being logged among the other ip's, but i still want to log my somewhere else. I tried a few different things, but i can't seem to get any of them to work. This is my code that logs all ips. <?php putenv("TZ=America/Los_Angeles"); $ip = $_SERVER['REMOTE_ADDR'] . " conneced on " . date('l jS \of F Y \a\t h:i:s A') . ".\n\n"; $handle = fopen("visitor_ip.txt", "a+"); fwrite($handle, $ip); fclose($handle); ?> Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/ Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 i would do this: if ($ip == $_SERVER['SERVER_ADDR'}) { exit(); } or if (!$ip == $_SERVER['SERVER_ADDR']) { execute your code } else { exit(); } or something of the sort, or identify your ip in a variable then Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/#findComment-631413 Share on other sites More sharing options...
ohdang888 Posted September 1, 2008 Share Posted September 1, 2008 do this: putenv("TZ=America/Los_Angeles"); $my_ip = "copy and paste your ip address"; if($_SERVER['REMOTE_ADDR'] != $my_ip){ $ip = $_SERVER['REMOTE_ADDR'] . " connected on " . date('l jS \of F Y \a\t h:i:s A') . ".\n\n"; $handle = fopen("visitor_ip.txt", "a+"); fwrite($handle, $ip); fclose($handle); } Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/#findComment-631416 Share on other sites More sharing options...
SN1P3R_85 Posted September 1, 2008 Author Share Posted September 1, 2008 I have tried things similar to this, and it hasn't seemed to work. I'll try again though. I am hosting my site on someone else server, so wouldn't $_SERVER['SERVER_ADDR'] be my servers ip? I want to exclude my local ip. Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/#findComment-631420 Share on other sites More sharing options...
ohdang888 Posted September 1, 2008 Share Posted September 1, 2008 my code should still work Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/#findComment-631441 Share on other sites More sharing options...
burn1337 Posted September 5, 2008 Share Posted September 5, 2008 well I did a script to log ips as well with me I'm behind a router so when I used $_SERVER['SERVER_ADDR']; it just used my router ip I had to set a variable to my ip and then have it check to make sure it wasn't that ip if ($ip == $myip) { echo 'welcome Server Admin'; } else { $do = "insert into db(IP, Time) values($ip, $Time)"; //+the query } Link to comment https://forums.phpfreaks.com/topic/122280-ip-logger-exlude-my-ip/#findComment-634348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.