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 -
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
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
Thank you for your response, but it's still the same, no file created.