PHP-written resource download anti-Leech sharing _ PHP Tutorial

Source: Internet
Author: User
PHP-written resource download anti-Leech sharing. 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 is a simple self-written PHP anti-theft function that is used to download and process PHP anti-Leech external resources over 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 http://jb51.net
*
*/
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 ();

The following is a simple self-written PHP anti-theft...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.