shortysbest Posted April 4, 2010 Share Posted April 4, 2010 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 https://forums.phpfreaks.com/topic/197517-help-with-code-notice-undefined-offset-0-in/ Share on other sites More sharing options...
Alex Posted April 4, 2010 Share Posted April 4, 2010 You should be using < not <=. for($x=0;$x<$linecount;$x++) Link to comment https://forums.phpfreaks.com/topic/197517-help-with-code-notice-undefined-offset-0-in/#findComment-1036648 Share on other sites More sharing options...
shortysbest Posted April 4, 2010 Author Share Posted April 4, 2010 You should be using < not <=. for($x=0;$x<$linecount;$x++) ahhh.. wow i feel like an idiot now.. i have been going over my code for about an hour trying to figure it out and it was the equal sign.. thanks. Link to comment https://forums.phpfreaks.com/topic/197517-help-with-code-notice-undefined-offset-0-in/#findComment-1036649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.