简体   繁体   English

我如何使用PHP跟踪热连接器的IP地址

[英]How can i track hot linkers ip address using php

have a picture in my server named /images/pic.jpg . 在我的服务器上有一张名为/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. 我想跟踪试图通过url lik www.domain.com/images/pic.jpg直接访问该图片的用户的IP地址。 I can track ip address of manual user by: 我可以通过以下方式跟踪手动用户的IP地址:

<?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. 您可以创建一个拦截PHP脚本,该脚本负责处理存储在特定文件夹中的所有图像请求。 Lets say all your images are located inside the images/ folder. 让我们说你的所有图像都位于images/文件夹内。 You would simply need to create a rewrite rule which will redirect all requests for files inside that folder to a PHP script. 您只需要创建一个重写规则,它将该文件夹中所有文件请求重定向到PHP脚本。

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. 请注意,此方法可能会对系统性能产生严重影响,因为所有对图像资源的请求现在都会因为每次都调用PHP而产生处理开销。

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. 如果他们直接访问图像,则无法使用PHP执行任何操作以跟踪它们,然后解析access_log并查看谁在请求文件。

Your best option is to use PHP to serve the image itself. 您最好的选择是使用PHP来为图像本身提供服务。 That way you can track who is requesting it through PHP. 这样,您就可以通过PHP跟踪谁在请求它。

Example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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