Retrieve visitor IP in a text file

barnabe0057 Posted messages 14328 Registration date   Status Contributor Last intervention   -  
barnabe0057 Posted messages 14328 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

Grandasse_ Posted messages 960 Registration date   Status Member Last intervention   610
 

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
barnabe0057 Posted messages 14328 Registration date   Status Contributor Last intervention   4 930
 

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

0