09月22日, 2014 3450次
所以获取镜像网站后台ip的方法如下:
(1)创建一个php文件,命名为ip.php ,在其添加如下代码:
<?php
$file = "ip.txt";//保存的文件名
$ip = $_SERVER['REMOTE_ADDR'];
$handle =fopen($file,'a');
fwrite($handle,"IP Address:");
fwrite($handle,"$ip");
fwrite($handle,"\n");
fclose($handele);
?>
之后保存,把ip.php上传到原网站根目录。
(2)之后访问:http://镜像网站域名/ip.php ,这样在原网站根目录下会生成一个ip.txt文本文件,其内容就包含了镜像网站后台ip地址。
(3)封镜像网站ip
在上一步获取到镜像网站后台ip后,就可以在原网站的空间管理中禁止此ip访问。也可以在原网站后台禁止此ip访问(很多网站系统,例如帝国cms,都有禁止ip访问的功能)。如果你不会禁止ip,也可以联系空间商,让其帮忙禁止ip。
注意事项:方法一比较简单,针对ip,但有时候镜像网站ip不固定,你刚禁止了ip,镜像网站的ip自动又改变了。这时候,我们就不能针对ip,只能针对域名了。下面的方法就是针对域名进行禁止。
这种方法是在原网站添加js代码判断域名,如果域名是原网站就正常显示,如果不是原网站域名,就跳转到原网站。
在网页的<head></head>部分添加下面代码:
<script type="text/javascript">
if (document.location.host != "www.lengxi.net") {
location.href = location.href.replace(document.location.host,'www.lengxi.net');}
</script>
其中的域名可以改成原网站,当判断域名不是原网站域名时,会自动跳转到原网站。
在网页<body></body>之间添加如下代码:
<style>
#fjx{display:none;width:100%;height:100%;margin:auto;background:#fff;z-index:1000;left:0;right:0;top:0;bottom:0;position:fixed;}
.fjx{display:none; text-align:center;font-size:18px;margin-top:200px;}
.fjx p{border-bottom:1px solid rgba(244,116,2,1);}
</style>
<script type="text/javascript">
if (document.location.host != "www.lengxi.net") {
window["document"]["writeln"]("<style>#fjx,.fjx{display:block!important;}</style>");
}
</script>
<div id="fjx"><div><p>冷曦博客提示:你现在浏览的网站是镜像网站</p>请访问原网站:www.lengxi.net </div></div>
有时候,镜像网站会屏蔽js代码,那么方法二、三的js就不能生效了。这时候我们正好可以利用js不生效,用div+css来区分镜像文件。方法原理和方法三正好相反,代码差不多。代码如下:
在网页<body></body>之间添加如下代码:
<style>
#fjx{width:100%;height:100%;margin:auto;background:#fff;z-index:1000;left:0;right:0;top:0;bottom:0;position:fixed;}.fjx{text-align:center;font-size:18px;margin-top:200px;}
.fjx p{border-bottom:1px solid rgba(244,116,2,1);}
</style>
<script type="text/javascript">
window["document"]["writeln"]("<style>#fjx,.fjx{display:none!important;}</style>");
</script>
<div id="fjx"><div class="fjx"><p>冷曦博客提示:你现在浏览的网站是镜像网站</p>请访问原网站:www.lengxi.net</div></div>
当访问原网站时,正常访问,当访问镜像网站时,由于镜像网站屏蔽js,所以这个div的文字就会显示出来。效果和方法三一样,效果如下图:
这样镜像网站就不能正常访问了。
if( $proxy_rs != 'nowamagic.net' || $proxy_rs != 'www.nowamagic.net' )
{
echo '非法反向代理访问';
//header('Location: http://www.nowamagic.net/');
exit;
}
public function proxy_filter()
{
/*
$svrUrl = 'http://' . $_SERVER['SERVER_NAME'].$_SERVER["PHP_SELF"];
if (!empty($_SERVER["QUERY_STRING"]))
{
$svrUrl .= "?".$_SERVER["QUERY_STRING"];
}
return $svrUrl;
*/
return $_SERVER['SERVER_NAME'];
}
RewriteBase /
php_value auto_append_file proxy.php
2.添加proxy.php文件
$f = getenv("HTTP_X_FORWARDED_FOR");
$server = getenv("HTTP_HOST");
if (($f!="")&&($server!="lengxi.net")&&($server!="www.lengxi.net")){
echo '本服务器禁止恶意反向代理!';
}
?>
暂无留言,赶快评论吧