Reaper0167 Posted March 2, 2010 Share Posted March 2, 2010 I can't get this to function properly. It gets the ip address, it the ip is a certain ip, it does not add it to the counter and displays the same count, otherwise add it to the counter and display it. With the code below, it just displays "0 times" <?php session_start(); $ip=$_SERVER['REMOTE_ADDR']; if ($ip != '184.59.170.237') { $guy = fopen('counterlog.txt', r); $dog = fread($guy, filesize('counterlog.txt')); echo 'This site has been visited ' . $dog+1 . ' times.'; fclose($guy); $guy = fopen('counterlog.txt', w); fwrite($guy, $dog+1); } else { $guy = fopen('counterlog.txt', w); fwrite($guy, 1); echo 'This site has been visited ' . $dog+0 . ' times.'; fclose($guy); } ?> This seems to not work properly Link to comment https://forums.phpfreaks.com/topic/193849-could-someone-please-help-me/ Share on other sites More sharing options...
teamatomic Posted March 2, 2010 Share Posted March 2, 2010 Look at this code and compare it to yours. session_start(); $log_file='counterlog.txt'; $ip=$_SERVER['REMOTE_ADDR']; if ($ip != '184.59.170.237') { $dog = file_get_contents("$log_file"); $doggy=$dog+1; echo "This site has been visited $doggy times."; file_put_contents("$log_file", $doggy); } else { $dog = file_get_contents("$log_file"); echo "This site has been visited $dog times."; } HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/193849-could-someone-please-help-me/#findComment-1020217 Share on other sites More sharing options...
Reaper0167 Posted March 2, 2010 Author Share Posted March 2, 2010 ooppss, i have the flu and am way out of it. thanks, i'll give it a shot. Link to comment https://forums.phpfreaks.com/topic/193849-could-someone-please-help-me/#findComment-1020226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.