Home >php教程 >php手册 >php实现禁止网外链接网址的方式查看网页

php实现禁止网外链接网址的方式查看网页

WBOY
WBOYOriginal
2016-06-21 09:05:591092browse

链接|网页

PHP实现禁止网外链接网址的方式查看网页
// 禁止网外链接(例如搜索引擎)查看网页内容

if(!empty($_SERVER['HTTP_REFERER']))
{
preg_match("/^(http:\/\/)?([^\/]+)/i",$_SERVER['HTTP_REFERER'], $matches);
$host = $matches[2];
if(($host=="211.152.50.35")||($host==www.phpv.net))
{
}
else
{
header("Location:http://www.phpv.net");
exit;
}
}
// 禁止直接输入网址查看网页内容
else
{
header("Location:http://www.phpv.net");
exit;
}

 


只有点击超链接(即) 打开的页面才有HTTP_REFERER环境变量, 其它如 window.open()、 window.location=...、window.showModelessDialog()等打开的窗口都没有HTTP_REFERER 环境变量; 这样的限制会使网站少很多活性。当然啦,鱼与熊掌不可兼得,呵呵。

这样写是不是更简洁些?
if(($host!="211.152.50.35")&&($host!=www.phpv.net)){
header("Location:http://www.phpv.net");
exit;
}

 



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn