刘华世的官方博客

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

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>";
}

 

posted @ 2015-09-04 16:37  刘华世的博客  阅读(1024)  评论(0编辑  收藏  举报
刘华世的官方博客