简体   繁体   中英

How can I get client's IP and hostname from all pages that are visited (including images) in my LAMP server?

I'm setting up a web server using apache and want to be able to get client's IP and hostname from any page they visit on the website without having to manually implement logging code in all the files.

I heard about .htaccess RewriteRule and tried that but it just redirects me to a page which logs that info as opposed to staying on the same page and automatically logging it in the background.

RewriteEngine On
RewriteRule ^flower.jpg$ info.php

Say I have a page info.php which logs that info and I have some other pages like welcome.html, flower.jpg, contact.html, game.png

What I expect: Whenever welcome.html, flower.jpg, contact.html or game.png is visited I expect info.php to auto load and log client's IP and hostname in the background.

What actually happened: I got redirected to info.php as opposed to staying on the same page(like flower.jpg as shown in the code)

How can I make sure I load info.php using htaccess in the background without getting redirected to it?

The Apache access log is at /var/log/apache2/access.log and contains the following for every request:

  • IP
  • Timestamp
  • User agent
  • File
  • Request method
  • Protocol
  • Status code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM