·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> php网站开发 >> php通过判断来源主机头进行防盗链

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

作者:佚名      php网站开发编辑:admin      更新时间:2022-07-23

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