简体   繁体   中英

How can i track hot linkers ip address using php

have a picture in my server named /images/pic.jpg . I want to track ip address of users who try to access that pic directly through url lik www.domain.com/images/pic.jpg. I can track ip address of manual user by:

<?php $ipAddress = $_SERVER['REMOTE_ADDR']; ?>

You could create an intercept PHP script which would be responsible for handling all requests for images which are stored in a specific folder. Lets say all your images are located inside the images/ folder. You would simply need to create a rewrite rule which will redirect all requests for files inside that folder to a PHP script.

RewriteRule images/(.+)\.(jpg|gif|png) images.php?image=$1.$2

This way you would still retain the ability to use your images inside markup the way you did before.

<img src="images/logo.png" />

Do take into consideration that this approach might have a heavy impact on your system performance because all requests for image resources are now creating processing overhead due to the fact that PHP is invoked every time.

If they are accessing the image directly you can't do anything with PHP to track them other then to parse your access_logs and see who is requesting the file.

Your best option is to use PHP to serve the image itself. That way you can track who is requesting it through PHP.

Example:

<img src="image.php?imagename.jpg">

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