Register user IP address, date and time

Is there a simple script or piece of code that I can add to my page to keep a log of each visitor, the date and time when they got to the page and IP address? And what would be the best way to do this ... javascript, php, something else?

EDIT:

Oh...

Here's what happened ... When I went to my server with FileZilla, all the domain names (about 20) were registered in my domain, so I found the one I needed and checked the logs, but it is mostly search engines.

But I just returned and accidentally scrolled down to things that were out of sight, and again there were domain names with www in front, like www.mydomain.com, and, of course, the magazines there are huge and have all one bit of information I need.

This happened because I found what mydomain.com was looking for, and of course I stopped looking. I did not know or did not see that there were a number of obsolete ... an honest mistake.

I still use this code because it is good and small, the logs are very dangerous and take time to download and view.

+7
source share
5 answers
$line = date('Ymd H:i:s') . " - $_SERVER[REMOTE_ADDR]"; file_put_contents('visitors.log', $line . PHP_EOL, FILE_APPEND); 

Consider also the entry $_SERVER['REQUEST_URI'] or other interesting information, possibly in a more standard format, as described in @Day.

+32
source
 <?php // include this piece of code in every page call // write in database row $log = array('time' => time(), 'ip' => $_SERVER['REMOTE_ADDR'], 'url' => $_SERVER['REQUEST_URI']); ?> 
+4
source

The simplest piece of code to add to your page is not code at all. Can I suggest something else? Try using the built-in web server logging mechanism instead of writing your own PHP code.

Apache and many other web servers can create logs in the Common Log Format (CLF), and many tools are available for analyzing such logs and drawing beautiful diagrams for you ( Webalizer , Awstats , etc.). The CLF log line looks like this giving you all the information you requested and much more:

 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 

See the appropriate documentation bit for your web server to configure logging and whirling:

+4
source

The most comprehensive is the Apache Access Log: Log Files → Access Log @ httpd.apache.org

+1
source

here is my little script for registering ip-addresses Do not forget to add below after the / HEAD tag also pay attention to make this work, it should be PHP, not HTML

 <?php include ('log-ip.php') ?> 

where do you want it to be called from

"Journal-ip.php"

 <?php $iplogfile = 'logs/ip-address-mainsite.html'; $ipaddress = $_SERVER['REMOTE_ADDR']; $webpage = $_SERVER['SCRIPT_NAME']; $timestamp = date('d/m/Y h:i:s'); $browser = $_SERVER['HTTP_USER_AGENT']; $fp = fopen($iplogfile, 'a+'); chmod($iplogfile, 0777); fwrite($fp, '['.$timestamp.']: '.$ipaddress.' '.$webpage.' '.$browser. "\n<br><br>"); fclose($fp); ?> 

and resault is a good HTML log file on the Internet. logs / IP address mainsite.html

 <!DOCTYPE html><!-- HTML5 --> <head> <body bgcolor="#000000"> <title>NZ Quakes - Main Web Site Log</title> </head> <body> <font color="#7FFF00"> <center>NZ Quakes - Main Web Site Log</center> <font color="gold"> <br><center> [01/04/2017 08:25:21]: 124.197.9.181 /index.php Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36 <br><br> 

below is an image of how it looks.

enter image description here

what do you think about it, I think it is clean and simple.

0
source

All Articles