Guardian-Mage Posted May 20, 2007 Share Posted May 20, 2007 I am making a hit counter that is SUPPOSED to only record unique IP addresses but it doesn't work. My script extracts an ip from a file and compares it with the current ip, but my keeps failing ,and says the IPs are not a match. the script at : http://wamboldt.ictonentertainment.com/Excalibur/Counter-TextBased+IP/iptest.php <?php /*============================================================================== File: counter.php Type: PHP: Hypertext Preprocessor Author: Brandon Wamboldt -Guardian Technology Desc: This is a simple text based flat file hit counter that counts each and every visit to a website that has an IP not already saved. ==============================================================================*/ //File Name $fileName = 'counter.txt'; $thisIP = $_SERVER["REMOTE_ADDR"]; //Check if file exists if (!file_exists($fileName)) { //If it doesn't exist create it $createFile = fopen($fileName, 'w') or die("Unable to open/create the counter.txt file. Please make sure that the permissions are correct"); //Write 0 into the file fwrite($createFile, 0); //Close the file fclose($createFile); } //Open the file in read mode $openFile = fopen($fileName, 'r') or die("Unable to open/write to the counter.txt file. Please make sure that the permissions are correct"); //Read the number from the file echo "<table border=\"1\"><tr><td>HIT #</td><td>IP of Hit</td><td>Your IP:</td><td>Match:</td></tr>"; while (!feof($openFile)) //Execute while the script isn't at the end of the file { echo "<tr>"; $curNum = fgets($openFile); //Read the hit number $ip = fgets($openFile); //Read the hit's IP address if ($ip == $thisIP) { echo "<tr><td>$curNum</td><td>$ip</td><td>$thisIP</td><td>Yes</td></tr> "; } else { echo "<tr><td>$curNum</td><td>$ip</td><td>$thisIP</td><td>NO</td></tr> "; } $blank = fgets($openFile); //Read the blank space in between hits } echo "</table>"; //Get the user's ip address if ($thisIP == $ip) { echo "pass"; } else { echo "fail"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/ Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 try <?php $ip = trim($ip); if ($thisIP == $ip) ?> as your IP's have spaces at the end Quote Link to comment https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/#findComment-257797 Share on other sites More sharing options...
radar Posted May 20, 2007 Share Posted May 20, 2007 Shouldn't it be something like -- if their ip is not in the list, then capture it right? My IP is not in the list, and it fails... and its cause of this.. //Get the user's ip address if ($thisIP == $ip) { echo "pass"; } else { echo "fail"; } try changing it to //Get the user's ip address if ($thisIP != $ip) { echo "pass"; } else { echo "fail"; } and see what it does.. Quote Link to comment https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/#findComment-257799 Share on other sites More sharing options...
Guardian-Mage Posted May 20, 2007 Author Share Posted May 20, 2007 MadTechie you are a genius, thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/#findComment-257803 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 your welcome Please click solved Quote Link to comment https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/#findComment-257805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.