检测页面是否合法链接过来

来源:互联网 发布:免费群发软件 编辑:程序博客网 时间:2024/05/02 04:41
<?php
$dbh = @mysql_connect("localhost:3306","root","");
if(!$dbh){die("error");}
mysql_query("set names utf8");
@mysql_select_db("music", $dbh);
if(count($_GET)>0)
{
/*
* 功能:检测页面是否合法链接过来
* 如果为非法,给予提示,并关闭窗口.
*/
$_SESSION['HTTP_REFERER']=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"";
function CheckURL()
{
//如果为手动输入的地址,则提示并关闭窗口
if($_SESSION['HTTP_REFERER']=="")
{
echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
echo "<script>";
echo "alert('请不要恶意攻击,我们已经追踪到你的ip');";
echo "window.close();";
echo "</script>";
exit;
}
}
CheckURL();
}
?>


0 0