Log user ip address, date and time

前端 未结 5 516
别跟我提以往
别跟我提以往 2020-12-24 15:32

Is there a simple script or piece of code I can add to my page to keep a log of every visitor, the date and time they hit the page and IP address? And what would be the bes

5条回答
  •  天命终不由人
    2020-12-24 16:12

    The simplest piece of code to add to your page is no code at all. So might I suggest "something else"? Try using your webserver's built-in request logging facility instead of writing some custom PHP code.

    Apache and many other webservers can produce logs in the Common Log Format (CLF) and there are many tools available to analyse such logs and draw pretty graphs for you (Webalizer, Awstats etc). A CLF log line looks like this which gives you all the information you asked for and 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 bit of documentation for your webserver for how to configure logging and give it a whirl:

    • Apache - access log
    • Nginx - HttpLogModule
    • Lighttpd - ModAccessLog
    • IIS - custom logging

提交回复
热议问题