PHP HTTP协议:防盗链

test.html:主界面

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:通过主页面进入的主机下的页面

 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:警告页面

1 <?php

2   

3   echo "别乱来";

4 ?>

 

你可能感兴趣的:(http协议)