How to Create an IP Logger

arsen15-26 Posted messages 208 Status Member -  
Gigatrappeur Posted messages 230 Status Member -
Hello,

Configuration: Windows 8 / Chrome 33.0.1750.146

I am just starting with PHP and I would like to keep a text file with the IP addresses and dates of visitors to my site, but I don't know how to do it. Could you enlighten me? Thank you.

1 answer

  1. Gigatrappeur Posted messages 230 Status Member 25
     
    Hello,

    use the super global variable:
    $_SERVER['REMOTE_ADDR']

    For more details, check this page http://www.php.net/manual/en/reserved.variables.server.php

    To write to a text file:
    use the function
    file_put_content 
    (https://www.php.net/manual/en/function.file-put-contents.php

    And to manage dates:
    the function
    date 
    (http://www.php.net/manual/en/function.date.php)
    Here's a little help:
    date('Y-m-d H:i:s');


    --
    Best regards,
    Gigatrappeur
    4