Heim > Backend-Entwicklung > PHP-Tutorial > php经过判断来源主机头进行防盗链

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

WBOY
Freigeben: 2016-06-13 12:24:19
Original
1092 Leute haben es durchsucht

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

check.php

<span style="color: #0000ff;"><span style="color: #800000;">html</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"><span style="color: #800000;">body</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"><span style="color: #800000;">form </span><span style="color: #ff0000;">action</span><span style="color: #0000ff;">="test.php"</span><span style="color: #ff0000;"> method</span><span style="color: #0000ff;">="post"</span><span style="color: #0000ff;">></span><span style="color: #000000;">    message</span><span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="text"</span><span style="color: #ff0000;"> name</span><span style="color: #0000ff;">="name"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="123456"</span> <span style="color: #0000ff;">/></span>    <span style="color: #0000ff;"><span style="color: #800000;">input </span><span style="color: #ff0000;">type</span><span style="color: #0000ff;">="submit"</span><span style="color: #ff0000;"> value</span><span style="color: #0000ff;">="submit"</span> <span style="color: #0000ff;">/></span><span style="color: #0000ff;"></span><span style="color: #800000;">form</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"></span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span><span style="color: #0000ff;"></span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></span></span></span></span></span>
Nach dem Login kopieren

test.php

<span style="color: #000000;">php</span><span style="color: #008080;">header</span>("Content-type:text/html;charset='utf8'"<span style="color: #000000;">);</span><span style="color: #008080;">error_reporting</span>(<span style="color: #ff00ff;">E_ALL</span><span style="color: #000000;">);</span><span style="color: #800080;">$url</span> = <span style="color: #008080;">parse_url</span>(<span style="color: #800080;">$_SERVER</span>['HTTP_REFERER'<span style="color: #000000;">]);</span><span style="color: #008000;">//</span><span style="color: #008000;">print_r($url);</span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$url</span>['host'] != "localhost"<span style="color: #000000;">){    </span><span style="color: #0000ff;">echo</span> "<script>alert('host error.');history.go(-1);</script>"<span style="color: #000000;">;    </span><span style="color: #0000ff;">exit</span>(0<span style="color: #000000;">);}</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{    </span><span style="color: #0000ff;">echo</span> "<script>alert('host right.');</script>"<span style="color: #000000;">;    </span><span style="color: #0000ff;">echo</span> "<h1>Hello World!</h1>"<span style="color: #000000;">;}</span>
Nach dem Login kopieren

 

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage