title: Error when trying to create a file based unique hit counter on PHP
body: <p>I'm learning to code in PHP by watching some youtube tutorials called "Beginner php tutorials" from the new Boston (maybe you know the channel). I was trying to create a unique hit counter using PHP but for some reason my code won't work. I hope you can help me out.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  
  function hit_counter() {
      $ip_address=$_SERVER['REMOTE_ADDR'];
      echo $ip_address;
      $ip_file=file('ip.txt');
  
      foreach ($ip_file as $ip) {
          $ip_single= trim($ip);
          if (@$ip_address!=$ip_single) {
              $ip_value=false;
              break;
          } else {
              $ip_value=true;    
          }
      }
  
      if (@ip_value==false) {
          $filename='count.txt';
          $handle=fopen($filename, 'r');
          $current=fread($handle, filesize($filename));
          fclose($handle);
  
          $count=$current+1;
  
          $handle=fopen($filename, 'w');
          fwrite($filename, $count);
          fclose($handle);
  
          $handle=fopen('ip.txt', 'a');
          fwrite($ip_file, @$ip_address.'\n');
          fclose($handle);
      }
  }
  
  ?&gt;
  </code></pre>