Public paste
Dork
By: Dork | Date: May 8 2008 00:03 | Format: None | Expires: never | Size: 794 B | Hits: 1146

  1. <?
  2. $filename = "test.txt";
  3. $replaced = "False";
  4. $hostname = "thuis";
  5. $clientip = $_SERVER['REMOTE_ADDR'];
  6.  
  7. $file = fopen($filename,"r+") or exit("Potsie dikkie het wil niet  ");
  8.  
  9. for ($i = 0; !FEOF($file); $i++) {
  10.         $contents .= fgets($file);
  11. }
  12.  
  13. fclose($file);
  14. $data = explode("n",$contents);
  15.  
  16. for ($i = 0; $i < count($data); $i++) {
  17.         $temp = explode("t",$data[$i]);
  18.  
  19.         if ($temp[0] == $hostname) {
  20.                 $oldip = $temp[4];
  21.  
  22.                 if ($oldip != $clientip) {
  23.                         $replaced = "True";
  24.                         $temp[4] = $clientip;
  25.                         $data[$i] = implode("t", $temp);
  26.                         // DOE HIER IETS ALS HET IP VERANDERD IS
  27.                 }
  28.         }              
  29.  
  30. }
  31. file_put_contents($filename,implode("n", $data));
  32.  
  33. echo "Oude IP: ".$oldip."<br>";
  34. echo "Nieuwe IP: ".$clientip."<br>";
  35. echo "Record bijgewerkt: ".$replaced."<br>";
  36. ?>