I needed to make a script that logged the hour, minute, day and year of a user connecting to a website. I was able to accomplish this using PHP and wanted to share it with you. It utilizes very simple TXT file storage.
Start a new file called log.php, and place this code into it:
$myFile = "log.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $_SERVER['REMOTE_ADDR'] . " : ";
fwrite($fh, $stringData);
$stringData = date('Y-m-d') . " : " . date('H:i') . "n";
fwrite($fh, $stringData);
fclose($fh);
To review this code… This uses fopen with an ‘a’ to append to the file to continue writing to the file everytime someone visits. It then pulls the remote address and date and writes it to the file.
The next step is to create the txt file: log.txt, and make sure it has proper permissions.
Last thing to do is test it and enjoy.
I hope that helps someone out there.
