Jump to content

Help with code. "Notice: undefined offset: 0 in"


shortysbest

Recommended Posts

I typed up a php unique hit counter for my website and it works perfectly fine, like how i want it to yet there's still an error popping up. I cannot seem to figure out what seems to be the problem, i'v tried everything.. here is the line that is causing the notice to appear.:

 

 if(intval($ipfile[$x])==$ip) 

 

again error is: Notice: Undefined offset: 0 in (then the directory and then points to that line of code)

 

Here is the entire counter code:

 

//open ip addres ip, count line
$ipfile = file("ips.txt");
$linecount = count($ipfile);
//open count file
$file = file_get_contents("count.txt");
$visitors = $file;
// set incremement boolean (should we add 1?)
$increment = true;
//users ip
$ip = $_SERVER['REMOTE_ADDR'];

if ($linecount==0)
$increment == true;
//start loop
for($x=0;$x<=$linecount;$x++)
{
//does ip match that in file?
if(intval($ipfile[$x])==$ip)
$increment = false;

}
//open new file, write new visitors value
if ($increment == true)
{

$filenew = fopen("count.txt",'w');

$visitorsnew = $visitors + 1;
fwrite($filenew,$visitorsnew);

$filenewip = fopen("ips.txt",'a');
fwrite($filenewip,$ip."\n");

}

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.