0
<?php

function hit_count()
{
      $ip_address = $_SERVER['REMOTE_ADDR'];
    $ip_file = file('ip.txt');        //file() function stores each line of that text file in form of  an array.
    foreach($ip_file as $ip)
    {
        //echo $ip.', ';
        $ip_single = trim($ip);       //space is there at the end of each line so you can use trim to remove the white space.

        if($ip_address == $ip_single)
        {
            $found = true; 
            break; 
        }else{$found = false;} 
    }
    if($found == true){ 
        echo 'found'; 
            }  else {echo 'not found';} 

}
?>

Error is:

Notice: Undefined variable: found in C:\xampp\htdocs\series\72Hit counter\uniqueHitcounter\count.php on line 18

its in this line if($found == true) is either true or false and its defined inside the same function. I am including and calling this function from a separate file.

hakas
  • 67
  • 1
  • 2
  • 5
  • $found is only set if the array $ip_file is not empty. – hellcode Aug 20 '15 at 12:48
  • yes so when the ip.txt file is empty it gives undefined notice so how to check if $ip_single is empty I tried this after the first if condition but doesn't help `elseif(empty($ip_single)){ $found=false; }` – hakas Aug 20 '15 at 13:40
  • Just insert `$found = false;` before `foreach`. – hellcode Aug 20 '15 at 14:21

0 Answers0