Jump to content

PHP IP Write To File Help


SirEddie

Recommended Posts

Hey all I have this script:

<?php
$file = "ip.txt";
$write = "".$_SERVER['REMOTE_ADDR']."|--|";
$open = fopen($file, 'a');
fwrite($open, $write);
?>

 

Which writes the visitors Ip to the file "ip.txt".

Now, it writes them across like this: 'IP IP IP IP IP IP IP" and it is confusing to read. I waas wondering, is there a way I can make it write them like this:?

IP

IP

IP

IP

 

Also, make it so it only writes the same IP once?

Link to comment
https://forums.phpfreaks.com/topic/51305-php-ip-write-to-file-help/
Share on other sites

Compleately Untested

--------------------------------

<?php
$str = file_get_contents('ip.txt');
$line = explode("\n", $str);
$flag = true;
foreach($line as $val)
  { 
    if($ip == $val)
      {
        $flag = false;
      }
  }
if($flag)
  {
    //Write the Files to the file
  }
?>


<?php
$str = file_get_contents('ip.txt');
$line = explode("\n", $str);
$flag = true;
foreach($line as $val)
  { 
    if($ip == $val)
      {
        $flag = false;
      }
  }
if($flag)
  {
   
$file = "ip.txt";
$write = $_SERVER['REMOTE_ADDR']."\n";
$open = fopen($file, 'a');

fwrite($open, $write);
  }
?>

 

I have it set like that.. But now it doesn't write any IP's.. Any ideas?

<?php
$str = file_get_contents('ip.txt');
$line = explode("\n", $str);
$flag = true;
foreach($line as $val)
  { 
    if($_SERVER['REMOTE_ADDR'] == $val)
      {
        $flag = false;
      }
  }
if($flag)
  {
   
$file = "ip.txt";
$write = $_SERVER['REMOTE_ADDR']."\n";
$open = fopen($file, 'a');

fwrite($open, $write);
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.