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

- 中国WEB开发者网络 (http://www.webasp.net)
-- 技术教程 (http://www.webasp.net/article/)
--- PHP实现禁止网外链接网址的方式查看网页 (http://www.webasp.net/article/14/13290.htm)
-- 作者:未知
-- 发布日期: 2004-09-21
// 禁止网外链接(例如搜索引擎)查看网页内容

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;
}




只有点击超链接(即<A href=...>) 打开的页面才有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;
}


webasp.net