首頁 > 後端開發 > php教程 > php透過判斷來源主機頭進行防盜鏈

php透過判斷來源主機頭進行防盜鏈

WBOY
發布: 2016-07-29 09:16:20
原創
1060 人瀏覽過

check.php

<span><</span><span>html</span><span>></span><span><</span><span>body</span><span>></span><span><</span><span>form </span><span>action</span><span>="test.php"</span><span> method</span><span>="post"</span><span>></span><span>    message</span><span><</span><span>input </span><span>type</span><span>="text"</span><span> name</span><span>="name"</span><span> value</span><span>="123456"</span><span>/></span><span><</span><span>input </span><span>type</span><span>="submit"</span><span> value</span><span>="submit"</span><span>/></span><span></</span><span>form</span><span>></span><span></</span><span>body</span><span>></span><span></</span><span>html</span><span>></span>
登入後複製

test.php

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

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

以上就介紹了php透過判斷來源主機頭進行防盜鏈,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板