Php file and image anti-Leech processing

Source: Internet
Author: User

Tragedy: since the server just submitted fails, it has to be rewritten ....

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: Copy code

<? Php

002 /**

003 *

004 * anti-Leech external resource download processing class

005 *

006 * @ author breeze <xrcc_bk@126.com>

007 * @ link http://blog.emtalk.net

008 *

009 */

010 class BurglarDow {

011 /**

012 * initial license download status

013 * @ var allow

014 * @ access private

015 */

016 private $ allow = false;

017 /**

018 * initial download address

019 * @ var dowUrl

020 * @ access private

021 */

022 private $ dowUrl = null;

023 /**

024 * Initial origin domain name

025 * @ var RemoteUrl

026 * @ access private

027 */

028 private $ RemoteUrl = null;

029 /**

030 * List of domain names used for initial license resources

031 * @ var allowUrl

032 * @ access private

033 */

034 private $ allowUrl = array ();

035 /**

036 * initial jump address

037 * @ var Location

038 * @ access private

039 */

040 private $ Location = null;

041

042 public function _ construct ($ dowUrl, $ Location, array $ allowUrl ){

043 // initial download address

044 $ this-> dowUrl = $ dowUrl;

045 // list of domain names used for initial license resources

046 $ this-> allowUrl = $ allowUrl;

047 // initial jump address

048 $ this-> Location = $ Location;

049

050 $ this-> RemoteUrl = @ parse_url ($ _ SERVER ['http _ referer']); // Obtain the origin domain name

051 if (! Is_array ($ this-> RemoteUrl ))

052 header ("HTTP/1.1 301 Moved Permanently ");

053 header ("Location:". $ this-> Location );

054

055 if (isset ($ this-> RemoteUrl ['host']) {

056 if (in_array ($ this-> RemoteUrl ['host'], $ this-> allowUrl) {// Determine whether the domain name is licensed

057 $ this-> allow = true; // The download license status is true.

058}

059}

060 unset ($ this-> allowUrl, $ this-> RemoteUrl); // release the memory variable

061}

062

063 /**

064 * anti-Leech resource download

065 * @ access public

066 * @ return mixed

067 */

068 public function dow (){

069 $ FileInfo = get_headers ($ this-> dowUrl, 1); // Obtain the remote file header information

070

071 if (true ===$ this-> allow) {// determine whether to permit resource download

072 // Determine whether the configuration file exists

073 if (is_file ('config. ini ')){

074 $ FileCon = parse_ini_file ('config. ini ');

075} else {

076 $ FileName = basename ($ FileInfo ['content-location']);

077 $ FileConStr = "FileName = {$ FileName} rnFileUrl = {$ FileInfo ['content-location']} rnFileSize = {$ FileInfo ['content-length']}";

078 $ handle = fopen ('config. ini ', "wb"); // create a file if the Config. ini file does not exist

079 if (fwrite ($ handle, $ FileConStr) = FALSE) {// write data to a file

080 echo "File creation failed ...";

081}

082 fclose ($ handle); // close an opened file pointer

083 $ FileCon = parse_ini_file ('config. ini ');

084}

085 if (! Empty ($ this-> dowUrl )){

086 $ fp = @ fopen ($ this-> dowUrl, "rb"); // read files in binary mode

087 if (! $ Fp)

088 exit ("Download a mistake. nn ");

089

090 // output remote resources

091 header ("Content-type: text/html; charset = utf-8 ");

092 header ('content-Description: File Transfer ');

093 header ('content-Type: application/octet-stream ');

094 header ('content-Disposition: attachment; filename = '. $ FileCon ['filename']);

095 header ("Accept-Ranges: bytes ");

096 header ('content-Transfer-Encoding: binary ');

097 header ('expires: 0 ');

098 header ('cache-Control: must-revalidate, post-check = 0, pre-check = 0 ');

099 header ('pragma: public ');

100 header ('content-Length: '. $ FileCon ['filesize']);

101 while (! Feof ($ fp )){

102 set_time_limit (0); // sets the maximum file execution time.

103 echo fread ($ fp, 1024); // output file

104 flush (); // OUTPUT BUFFER

105 ob_flush (); // content in the output buffer

106}

107 fclose ($ fps );

108} else {

109 header ("HTTP/1.1 404 Not Found ");

110}

111} else {

112 header ("HTTP/1.1 301 Moved Permanently ");

113 header ("Location:". $ this-> Location );

114}

115}

116}

117 // remote resource address

118 $ dowUrl = '/qq/QQ5.1/10055/QQ5.1.exe ';

119 // jump address

120 $ Location = 'http: // www.111cn.net ';

121 // list of licensed domain names

122 $ allowUrl = array (

123 'blog .emtalk.net ',

124 );

125 $ BurglarDow = new BurglarDow ($ dowUrl, $ Location, $ allowUrl );

126 $ BurglarDow-> dow ();


If you have any shortcomings, I hope you can give more advice;

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.