繁体   English   中英

如何使用php和htaccess跟踪热连接器的ip地址

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

我正在尝试使用php和htaccess跟踪hotlinkers的ip地址。

.htaccess文件:

RewriteEngine on 
RewriteRule images/(.+)\.(jpg|gif|png) images.php 

images.php

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

    $statement=$db->prepare("INSERT INTO `ipaddress` (`ip` )
            VALUES (?)");
    $statement->execute(array($ipAddress));     

?>

现在,用户请求像这样的图像www.domain.com/images/image.jpg它将重定向到images.php并跟踪他们的ips。 我面临的问题是我的页面内部没有显示图像(原因是htaccess将其重定向到images.php)。 我该如何解决这个问题?

以下是有关此问题的上一个问题的链接:

我不是htaccess的专家所以需要更多的解释

谢谢

如果你想记录IP然后再提供图像,那么这样的事情可能会:

.htaccess文件:

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

images.php:

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

    $statement=$db->prepare("INSERT INTO `ipaddress` (`ip` )
            VALUES (?)");
    $statement->execute(array($ipAddress));

    $ext = strtolower(end(explode('.', $_GET['image'])));

    if($ext == 'gif') {
        $type = "gif";
    }
    else if($ext == 'jpg') {
        $type = "jpeg";
    }
    else if($text == 'png') {
        $type = "png";
    }
    else {
        $type = "binary";
    }

    header("Content-type: image/$type");
    readfile("images/" . $_GET['image']);

?>

您可能需要在此处调整路径以确保在.htaccessimages.php中正确指向所有文件。

暂无
暂无

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

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