這里分析了php的簡單防盜鏈實現方法。分享飛大家供大家參考。具體如下:
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"){//此處可替換成當前使用的域名 echo "驗證錯誤!"; echo "<script>alert('連接失敗');location.href='index.php';</script>"; exit; } print("</pre>");
希望本文所述對大家php程序設計有所幫助。
新聞熱點
疑難解答
圖片精選