Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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