How to save the IP of who visited my site in a text file?

2

I'm using the code below, but it only writes ":: 1" to the file.

<?php 
$arquivo = "ips.txt";
$file = fopen($arquivo,"a"); 
$string = $_SERVER['REMOTE_ADDR']  . "\n";
$fp = fwrite($file,$string);
fclose($file);
?>

Is it because I'm on localhost?

    
asked by anonymous 09.09.2014 / 18:19

1 answer

3

using the code placed in the question ... I remembered it this way now ...

<?php
    $arquivo = "ips.txt";
    $string = $_SERVER['REMOTE_ADDR']  . "\n";
    // ao usar FILE_APPEND para adicionar ao ficheiro estamos a colocar no fim do mesmo
    // e com o LOCK_EX trata das gravações concurrentes que podem acontecer
    file_put_contents($arquivo, $string, FILE_APPEND | LOCK_EX);
?>

:: 1 is the IPv6 notation for 127.0.0.1

    
09.09.2014 / 18:28