title: php read from text file and combine duplicate entries
body: <p>I have this little piece of code I'm just testing out that basically redirects a user if their IP doesn't match the predefined IP and if it doesn't match write that IP into a text file.</p>
  
  <pre><code>$file = fopen("ips.txt", "w");
  
  if ($ip == "iphere") {
      echo "Welcome";
      fclose($file);
  } else {
      header('Location: http://www.google.com');
      fwrite($file, "\n" . $ip);
      if ($file) {
          $array = explode("\n", fread($file, filesize("ips.txt")));
      }
  
      $result = print_r($array, TRUE);
  
      fclose($file);
  }
  </code></pre>
  
  <p>What I want to do is take the IPs that I'm writing to the text file, put them all into an array to find the duplicates, make note of the duplicates, filter them out, then write them back into that file or another txt file, but I'm stuck and not sure where to go from here.</p>