Jump to content

[SOLVED] since when does 1 not equal one?


Guardian-Mage

Recommended Posts

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";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/52253-solved-since-when-does-1-not-equal-one/
Share on other sites

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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.