The anti-hotlink code we describe here only focuses on PHP solutions. Of course, if you have server management rights or htaccess file operations, I recommend not to use PHP anti-hotlink code.
Let’s look at the simplest one first
The following is the code implemented in php. xxx.mp3 is the actual address of your music file. When distributing it to the outside world, only the php address is disseminated, and the mp3 address is not disclosed to the outside world
<🎜>$ADMIN[defaulturl] = "http://www.bKjia.c0m/404.htm";//The address returned by the hotlink<🎜>
$okaysites = array("http://www.bKjia.c0m/","http://bKjia.c0m"); //Whitelist <🎜>
$ADMIN[url_1] = "http://www.bKjia.c0m/download/";//Download location 1<🎜>
$ADMIN[url_2] = "";//Download location 2, and so on<🎜>
<🎜>$reffer = $HTTP_REFERER;<🎜>
if($reffer) {<🎜>
$yes = 0;<🎜>
while(list($domain, $subarray) = each($okaysites)) {<🎜>
if (ereg($subarray,"$reffer")) {<🎜>
$yes = 1;<🎜>
}<🎜>
}<🎜>
$theu = "url"."_"."$site";<🎜>
if ($ADMIN[$theu] AND $yes == 1) {<🎜>
header("Location: $ADMIN[$theu]/$file");<🎜>
} else {<🎜>
header("Location: $ADMIN[defaulturl]");<🎜>
}<🎜>
} else {<🎜>
header("Location: $ADMIN[defaulturl]");<🎜>
}<🎜>
<🎜>?>
There are many ways to implement anti-hotlinking. This article only talks about using PHP to implement it. For example, some sites generate HTML, which is not very convenient. We can operate it in iis, apache, and htaccess.
http://www.bkjia.com/PHPjc/631618.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631618.htmlTechArticleThe anti-hotlink code we describe here only focuses on PHP solutions. Of course, if you have server management rights or htaccess I recommend not using PHP hotlink protection for file operations. Let’s take a look at the most...
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn