This article mainly introduces PHP-written resource download anti-leech sharing. For more information, see
This article mainly introduces PHP-written resource download anti-leech sharing. For more information, see
I have been writing a PHP anti-leech external resource download handler in the past few days. I just completed the compilation last night and encountered some problems. I will not go into detail here;
The following are self-written simple PHP anti-leech processing classes (recompile them into class files for later improvement );
The Code is as follows:
/**
*
* Anti-leech external resource download processing class
*
* @ Link
*
*/
Class BurglarDow {
/**
* Initial license Download Status
* @ Var allow
* @ Access private
*/
Private $ allow = false;
/**
* Initial
* @ Var dowUrl
* @ Access private
*/
Private $ dowUrl = null;
/**
* Initial origin Domain Name
* @ Var RemoteUrl
* @ Access private
*/
Private $ RemoteUrl = null;
/**
* List of domain names used for initial license Resources
* @ Var allowUrl
* @ Access private
*/
Private $ allowUrl = array ();
/**
* Initial jump address
* @ Var Location
* @ Access private
*/
Private $ Location = null;
Public function _ construct ($ dowUrl, $ Location, array $ allowUrl ){
// Initial
$ This-> dowUrl = $ dowUrl;
// List of domain names used for initial licensed Resources
$ This-> allowUrl = $ allowUrl;
// Initial jump address
$ This-> Location = $ Location;
$ This-> RemoteUrl = @ parse_url ($ _ SERVER ['HTTP _ referer']); // obtain the origin Domain Name
If (! Is_array ($ this-> RemoteUrl ))
Header ("HTTP/1.1 301 Moved Permanently ");
Header ("Location:". $ this-> Location );
If (isset ($ this-> RemoteUrl ['host']) {
If (in_array ($ this-> RemoteUrl ['host'], $ this-> allowUrl) {// determines whether the domain name is licensed.
$ This-> allow = true; // The download license status is true.
}
}
Unset ($ this-> allowUrl, $ this-> RemoteUrl); // release the memory variable
}
/**
* Anti-leech resource download
* @ Access public
* @ Return mixed
*/
Public function dow (){
$ FileInfo = get_headers ($ this-> dowUrl, 1); // obtain the remote file header information
If (true ===$ this-> allow) {// determine whether to permit resource download
// Determine whether 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 = {$ FileInfo ['content-location']} \ r \ nFileSize = {$ FileInfo ['content-length' ]} ";
$ Handle = fopen ('config. ini ', "wb"); // create a file if the Config. ini file does not exist.
If (fwrite ($ handle, $ FileConStr) = FALSE) {// write data to a file
Echo "File creation failed ...";
}
Fclose ($ handle); // close an opened file pointer
$ FileCon = parse_ini_file ('config. ini ');
}
If (! Empty ($ this-> dowUrl )){
$ Fp = @ fopen ($ this-> dowUrl, "rb"); // read files in binary mode
If (! $ Fp)
Exit ("Download a mistake. \ n ");
// Output Remote Resources
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); // sets the maximum file 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: // jb51.net ';
// List of Licensed domain names
$ AllowUrl = array (
'Jb51. net ',
);
$ BurglarDow = new BurglarDow ($ dowUrl, $ Location, $ allowUrl );
$ BurglarDow-> dow ();
,