PHP HTTP協議:防盜鏈

test.html:主界面php

1 <html>
2     <head>
3         <meta http-equiv="content-type" content="text/html;charset=utf-8">
4     </head>
5     <body>
6         <h1> test</h1>
7         <a href="http://localhost:8082/import.php"> 查看圖片</a>
8     </body>
9 </html>

import.php:經過主頁面進入的主機下的頁面html

 1 <?php
 2 
 3   //獲取Referer
 4   if(isset($_SERVER['HTTP_REFERER']))
 5   {
 6       //取出來referer,判斷$_SERVER['HTTP_REFERER']是否以http://localhost開頭的
 7 
 8       if(0==strpos($_SERVER['HTTP_REFERER'],"http://localhost"))
 9     {
10         echo "大隊了";
11     }else{
12       header("Location:warning.php");    
13     }
14   }else{
15       header("Location:warning.php");    
16     }
17   echo "恭喜你進來了";
18 ?>

warning.php:警告頁面ui

1 <?php
2   
3   echo "別亂來";
4 ?>
相關文章
相關標籤/搜索