PHP Anti-theft chain external resources Download processing class
The following is a self-written simple PHP anti-theft chain processing class (re-organized into class files for later improvement);
/** * * Anti-theft chain external resources Download processing class */class burglardow{/** * Initial license Download status * @var allow * @access private */private $allow = false;/** * Initial download Address * @var Dowurl * @access private */private $DOWURL = null;/** * Initial route Domain Name * @var remoteurl * @access private */private $REMOTEURL = null;/** * Initial license resource access domain Name list * @var al Lowurl * @access private */private $ALLOWURL = Array ();/** * Initial Jump Address * @var location * @access PR Ivate */private $Location = null;public function __construct ($DOWURL, $Location, array $allowUrl) {//Initial download address $this-> Dowurl = $DOWURL;//The initial license resource takes the domain Name list $this->allowurl = $ALLOWURL;//initial hop address $this->location = $Location; $this Remoteurl = @parse_url ($_server[' http_referer '); Get the header if (!is_array ($this->remoteurl)) headers ("http/1.1 301 Moved Permanently"), Header ("Location:" $this. Location), if (Isset ($this->remoteurl[' host ')) {if (In_arrAy ($this->remoteurl[' host '], $this->allowurl)) {//Determine whether to come to the licensed domain name $this- >allow = true; Download License Status: True}}unset ($this->allowurl, $this->remoteurl); Free memory Variable}/** * Anti-theft chain resource Download * @access public * @return Mixed */public function Dow () {$FileInfo = Get_headers ($this-&G t;dowurl,1); Gets the remote file header information if (true = = = $this->allow) { Determine whether to license the download resource//Determine if the configuration file exists if (is_file (' Config.ini ')) {$FileCon = Parse_ini_file (' Config.ini ');} else{$FileName = basename ($FileInfo [' content-location ']); $FileConStr = "FileName = {$FileName}\r\nfileurl = {$FileIn fo[' content-location ']}\r\nfilesize = {$FileInfo [' content-length ']} "; $handle = fopen (' Config.ini '," WB "); Config.ini file does not exist then create file if (fwrite ($handle, $FileConStr) = = Fals E) {//data write to file echo "File creation failed ...";} Fclose ($handle); Close an open file pointer $filecon = parse_ini_file (' Config.ini ');} if (!empty ($ $this->dowurl)) {$fp = @fopen ($ $this->dowurl, "RB"); Binary mode reads the file if (! $fp) Exit ("Download a mistake.\n\n");//outputs the remote resource header ("Content-type:text/html;charset=utf-8" Header (' Content-description:file Transfer '); header (' Content-type:application/octet-stream '); Header (' Content-disposition:attachment; Filename= '. $FileCon [' FileName ']; Header ("Accept-ranges:bytes"); header (' content-transfer-encoding:binary '); Header (' expires:0 '); header (' cache-control:must-revalidate,post-check=0,pre-check=0 '); header (' Pragma:public '); Header (' content-Length: '. $FileCon [' FileSize ']); while (!feof ($fp)) {set_time_limit (0); Set file maximum execution time echo fread ($FP, 1024); Output file flush (); Output buffer Ob_flush (); Content in the output buffer}fclose ($FP);} Else{header ("http/1.1 404 Not Found");}} Else{header ("http/1.1 301 Moved permanently"); Header ("Location:". $this->location);}}} Remote Resource Address $dowurl = ' http://dldir1.qq.com/qqfile/qq/QQ5.1/10055/QQ5.1.exe ';//jump address $location = ' http:// Www.scutephp.com ';//License routing domain list $allowurl = array (' blog.emtalk.net ',); $BurglarDow = new Burglardow ($DOWURL, $Location, $ ALLOWURL); $BurglarDow Dow ();