不同ip打开网站不跳转实现url相同,但是j页面展示内容不同!
比如说:上海那边打开网站是:春花秋月何时了……但是其他地方打开后一看:关关雎鸠 ,在河之洲……
教程开始:
一共需要3个文件,放在根目录, 两个文件夹:a文件夹和b文件夹(自己建立)。
原理:访客进入网站,网站自动检测ip,如果是在ip库里的就展示b文件夹的内容。通过php调用而且利用伪静态让原本显示为
chenyu.me/b/1.html显示为chenyu.me/1.html
如果是ip库里没有的,就展示a文件夹的内容。通过php调用而且利用伪静态让原本显示为chenyu.me/a/1.html显示为chenyu.me/1.html
如果你访问chenyu.me/333/1.html这个文件只在a目录下有,但是b目录下没有就直接跳转到b目录的首页自动读取/b/index.html。
首先是.htaccess文件
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteRule ^(.*).html index.php?p=$1&d=0
RewriteRule ^(.*)/$ index.php?p=$1&d=1
</ifmodule>
Nginx:
rewrite ^/(.*).html /index.php?p=$1&d=0;
rewrite ^/(.*)/$ /index.php?p=$1&d=1;
其次是根目录下的index.php
[ppblock ex=”扫码关注本站公众号,回复“遇”,获取验证码” pwd=”遇”]
<?php
//获得IP
$myip=ip2long(getenv("REMOTE_ADDR"));
//读取IP文件
$fp= file("ip.txt");
$p=$_GET['p'];
$d=$_GET['d'];//是否为栏目
if($d=='')//首页
{
$p=$p."/index.html";
}
else if($d==1) //栏目
{
$p=$p."/index.html";
}
else
{
$p=$p.".html";
}
$flag=0;
//循环比对
for ($i=0;$i<count($fp);$i++)
{
$ip=explode('|',$fp[$i]);
$ip1=ip2long($ip['1']);
$ip2=ip2long($ip['2']);
if($myip >= $ip1 && $myip <= $ip2)
{$flag=1;}
}
//IP有存在与IP库中 跳转到指定页面,
$flag==0?$mysite="a":$mysite="b";
$fileHtml=$mysite.'/'.$p;
if(file_exists($fileHtml))
include($fileHtml);
else
{
include($mysite.'/index.html');
}
?>
[/ppblock]
最后是ip.txt:|开始IP|终止IP
示例:
|192.168.1.1|192.168.1.255
© 版权声明
分享是一种美德,转载请保留原链接
THE END
暂无评论内容