Jump to content

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);
  }
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.