php簡單防盜鏈驗證實現(xiàn)方法

字號:


    這里分析了php的簡單防盜鏈實現(xiàn)方法。分享飛大家供大家參考。具體如下:
    index.php頁面如下:
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en" />
    <meta name="GENERATOR" content="PHPEclipse 1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>防盜鏈</title>
    </head>
    <body>
     <form action="check.php" method="post">
     提交信息:<input type="text" name="name" value=""/>
     <input type="submit" name="submit" value="提交"/>
     </form>
    </body>
    </html>
    check.php頁面如下:
    $urlar=parse_url($_SERVER['HTTP_REFERER']);
     print("<pre>");
     print_r($urlar);
     print_r($_SERVER['HTTP_REFERER']);
     if($urlar['host']!="localhost"){//此處可替換成當(dāng)前使用的域名
     echo "驗證錯誤!";
     echo "<script>alert('連接失敗');location.href='index.php';</script>";
     exit;
     }
     print("</pre>");
     希望本文所述對大家php程序設(shè)計有所幫助。