php 禁止 URL 直接访问 php文件

通过判断访问来源来实现。
$fromurl="http://www.111.com/index.php"; //只能从这个地址访问
if( $_SERVER['HTTP_REFERER'] != $fromurl )
{
   header("Location:".$fromurl);
   exit;
}

不好意思。理解错误。。。改一下代码。。

$fromurl="http://www.111.com/index.php"; //跳转往这个地址。
if( $_SERVER['HTTP_REFERER'] == "" )
{
   header("Location:".$fromurl);
   exit;
}

 

posted @ 2014-08-06 11:16  龙昊雪  阅读(2303)  评论(0编辑  收藏  举报