1. Simple anti-hotlinking
Copy the code The code is as follows:
$ADMIN[defaulturl] = "http://jb51.net/404.htm";//The address returned by the hotlinking
$okaysites = array("http://jb51.net/","http://www.jb51.net"); //Whitelist
$ADMIN[url_1] = "http://jb51.net/temp/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]");
}
?>
Copy the code The code is as follows:
//Place the root directory of the downloaded software relative to the current script directory
$ fileRelPath = "../../software";
//Exception allows the connection URL, note: your own domain name does not need to be filled in, set it to be sure to download,
// Empty string ("") means direct input URL download situation
$excludeReferArr = array("www.wjb51.net", "wjb51.net");
chdir($fileRelPath);
$fileRootPath = getcwd() ."/";
$filePath=$HTTP_GET_VARS ["file"];
$url=parse_url($_SERVER["HTTP_REFERER"]);
if($url[host]!=$_SERVER["HTTP_HOST"] && !in_array($referHost, $excludeReferArr)){
?>
The above has introduced a summary of the common methods of anti-theft PHP anti-hotlinking, including anti-theft content. I hope it will be helpful to friends who are interested in PHP tutorials.