這裡分析了php的簡單防盜鏈實作方法。分享飛大家供大家參考。具體如下:
index.php頁面如下:
<html> <head> <meta http-equiv="Content-Language" c /> <meta name="GENERATOR" c /> <meta http-equiv="Content-Type" c /> <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 class="brush:php;toolbar:false">"); print_r($urlar); print_r($_SERVER['HTTP_REFERER']); if($urlar['host']!="localhost"){//此处可替换成当前使用的域名 echo "验证错误!"; echo "<script>alert('连接失败');location.href='index.php';</script>"; exit; } print("");