Maison > développement back-end > tutoriel php > php经过判断来源主机头进行防盗链

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

WBOY
Libérer: 2016-06-13 12:24:19
original
1092 Les gens l'ont consulté

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>
Copier après la connexion

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>
Copier après la connexion

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal