IP logging function / IP logger scriptThis is just a simple PHP IP logging function / script which can be added to any already existing .php or .html file to log the date and time that the page was accessed and the IP address of the one who accessed it to a file on your server. This function / script checks to see if the logfile ends in either .html or .htm extensions as supposed to .txt or whatever so it can format the logfile correctly. The logFile must have writable permissions in order for the script to be able to write the data to it. This script will require that the log file have writable permissions. You can use this function as a whole script if you like. Below are two possable ways to launch this script.
Just remember, however you include the code, the HTML page's extension will have to be changed to .php (or .phtml). If you want you can also use an <iframe> tag to load the PHP file like so: (NOTE: page with the <iframe> tag can have a .html extension). For an example of a script that uses an iframe tag see the 'Photo of the day' script in the PHP > Miscellaneous section.
If you only want to use this function in an already existing script then just add the function WITHOUT the opening and closing PHP tags ( <?php ?>) to your script and call it by placing the function call (logIp();) wherever you want it to fire in your script.
|