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

}

Link to comment
Share on other sites

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.