Retrieve visitor IP in a text file

barnabe0057 Posted messages 14329 Registration date   Status Contributor Last intervention   -  
barnabe0057 Posted messages 14329 Registration date   Status Contributor Last intervention   -

Hello,

The IP address displays correctly in the browser, but my file_put_contents does not create any file in the current directory.

I don't understand, I changed the folder permissions to 777 but it has no effect.

<?php // Display the visitor's IP address $add = $_SERVER['REMOTE_ADDR']; echo 'Your IP address ==>> ' . '[ ' . $add .' ]'; file_put_contents('ip_address.txt', $add); ?> 

Thank you for your help.


1 answer

  1. Grandasse_ Posted messages 985 Registration date   Status Member Last intervention   618
     

    Hello,

    Try with :

    $add = $_SERVER[REMOTE_ADDR]; file_put_contents('ip_address.txt', $add . PHP_EOL, FILE_APPEND); 

    Found and adapted from here: https://stackoverflow.com/a/6837689


    0
    1. barnabe0057 Posted messages 14329 Registration date   Status Contributor Last intervention   4 929
       

      Thank you for your response, but it's still the same, no file created.

      0