In this tutorial I will show you how to make a PHP script for recording IP, number of visits and the time of last visit.
First of all you need to make a file e.g: ips.txt with write rights: chmod 777;
In the code above we are declaring the name of the file, an array $rows, $sep as a ^ separator and in $ip the curent ip of the client.
We verify if the file exists, then we take the rows ignoring new lines and blank spaces and we count the rows. After that we check if the current ip is already registered in the file, using explode we separate data from each row. If the ip exists already we increment the nr. of views and modify the time.
IP: ‘. $row. ‘
Nr. of visits: ‘. $row. ‘
Last viewed date: ‘. date(‘j-M-Y, H:i’, $row);
else echo ‘File ‘. $file. ‘ does not exists.’;
That’s it, now you can view who access your website, when and how many times.
Thanks for reading!
Leave a Reply