Search code examples
phpwordpresssecurityjoomladdos

How to store IP address that accesses a specific url into a file


I'm no coder and I'm running into an issue. What I would like to do is to store into a file all the IPs that try accessing specific URLS so that I can build a list of IPs of people that are either trying to see if my site is made with a specific CMS or try to hack their way into it.

I know I can access such data in the server log files but automating the task would save me a lot of time in the long run.

Is there so code that I could add on the specific URLs that would do this?


Solution

  • <?php
    $pathToLogFile="";
    file_put_contents($pathToLogFile, "\nIP Address". $_SERVER["REMOTE_ADDR"],FILE_APPEND)
    ?>
    

    Remember to provide an absolute path if you're placing this file in multiple directories, and make sure you initialize a blank file at that path