0

一个随机网站决定通过以下代码加载我的一个网址...

<img src="http://mysite.com/" width="1" height="1" />

我尝试添加一个 javascript framebreaker 来检查和中断,但这不适用于此。如何确保我的网站摆脱这种情况并显示为完整的浏览器而不是隐藏?他们正在消耗宝贵的带宽。谢谢

这是我已经像往常一样从头脑中尝试过的帧中断代码......

if(stristr($_SERVER['HTTP_REFERER'],"badsite.com") == true){
echo '<script language="Javascript">
<!-- 
if (top.location != self.location) 
top.location.replace(self.location);
}
//--> 
</script>';
}
4

3 回答 3

2

你不能。

HTML 被解析为图像。这会引发错误,并且不会执行您可能提供给它的任何客户端代码。

于 2013-01-07T11:17:37.113 回答
0

正如其他人所说,这不是帧中断,也不涉及 PHP 代码。

你唯一能做的就是在你的服务器的配置中,比如添加一个规则来强制请求拥有一个正确的 HTTP Referer。

如果您使用 Apache,您可以为此在服务器上上传一个.htaccess(链接在我很久以前写的博客文章上)

# Prevent Files image hotlinking and bandwidth stealing
RewriteEngine On
RewriteBase /blog/wp-content/uploads/
RewriteCond %{HTTP_REFERER} !^http://www.exemple.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|swf|flv|png)$ / [F,L]

编辑:在你的情况下,你可以做

RewriteCond %{HTTP_REFERER} ^http://nasty-site.exemple.com/.*$ [NC]
RewriteRule .* http://localhost/

这样,来自http://nasty-site.exemple.com/的所有流量都被重定向到 localhost 并且没有人被打扰

于 2013-01-09T14:15:42.413 回答
0

是的你可以

简单的一步一步:

1-创建一个与以下内容相同的文件夹:images

2-在图像文件夹中创建一个名称为:image_folder 的文件夹并将您的图像文件放在“image_folder”中

3-通过此内容创建一个 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php 
</IfModule>

4- 通过以下内容在 images 文件夹中创建 index.php:

    <?
$filename  = urldecode(end(explode('/',$_SERVER['REQUEST_URI'])));
$subname = current(explode('.',$filename));

$extention = end(explode('.',$filename));
switch ($extention) {
    case 'gif':
        $mime = 'image/gif';
        break;
    case 'jpg':
    case 'jpeg':
    case 'jpe':
        $mime = 'image/jpeg';
        break;
    case 'png':
        $mime = 'image/png';
        break;
    case 'ico':
        $mime = 'image/x-icon';
        break;
    default:
        header("HTTP/1.0 404 Not Found");
        echo('image not finded');
        exit;
        break;
}
if(is_file("image_folder/".$filename)){
    header("Content-type: ".$mime);
    readfile("image_folder/".$filename);
}else{
    header("HTTP/1.0 404 Not Found");
    echo('image not finded');
}

解释:现在您可以轻松地在 index.php 中查看referer

于 2013-01-09T14:28:04.737 回答