码迷,mamicode.com
首页 > Web开发 > 详细

php通过判断来源主机头进行防盗链

时间:2015-09-04 17:02:42      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

check.php

<html>
<body>
<form action="test.php" method="post">
    message<input type="text" name="name" value="123456" />
    <input type="submit" value="submit" />
</form>
</body>
</html>

test.php

<?php
header("Content-type:text/html;charset=‘utf8‘");
error_reporting(E_ALL);

$url = parse_url($_SERVER[‘HTTP_REFERER‘]);
//print_r($url);
if($url[‘host‘] != "localhost"){
    echo "<script>alert(‘host error.‘);history.go(-1);</script>";
    exit(0);
}else{
    echo "<script>alert(‘host right.‘);</script>";
    echo "<h1>Hello World!</h1>";
}

技术分享

 

php通过判断来源主机头进行防盗链

标签:

原文地址:http://www.cnblogs.com/myall/p/4781924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!