PHPの書く資源は盗難防止チェーン類をダウンロードして分かち合います

5378 ワード

ここ数日PHP盗難防止チェーンの外部資源ダウンロード処理関数を書いています.昨日の夜、作成が終わったばかりで、途中でいくつかの問題に遭遇しました.ここでは詳しく説明しません.以下は自作の簡単なPHP盗難防止チェーン処理類(後で改善するためにクラスファイルに再整理して作成する);
 
  
/**
 *
 *
 *
 * @link   http://jb51.net
 *
 */
class BurglarDow{
 /**
     *
     * @var    allow
     * @access private
     */
 private $allow      =  false;
 /**
     *
     * @var    dowUrl
     * @access private
     */
 private $dowUrl     =  null;
 /**
     *
     * @var    RemoteUrl
     * @access private
     */
 private $RemoteUrl  =  null;
 /**
     *
     * @var    allowUrl
     * @access private
     */
 private $allowUrl   =  array();
 /**
     *
     * @var    Location
     * @access private
     */
 private $Location   =  null;

 public function __construct($dowUrl,$Location,array $allowUrl){
  //
  $this->dowUrl   = $dowUrl;
  //
  $this->allowUrl = $allowUrl;
  //
  $this->Location = $Location;

  $this->RemoteUrl = @parse_url($_SERVER['HTTP_REFERER']);                                                      //
  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)){                                                   //
    $this->allow  = true;                                                                                 // :
   }
  }
  unset($this->allowUrl,$this->RemoteUrl);                                                                      //
 }

 /**
  *
  * @access public
  * @return mixed
  */
 public function dow(){
  $FileInfo = get_headers($this->dowUrl,1);                                                                     //

  if(true === $this->allow){                                                                                    //
   //
   if(is_file('Config.ini')){
    $FileCon = parse_ini_file('Config.ini');
   }else{
    $FileName   =  basename($FileInfo['Content-Location']);
    $FileConStr = "FileName  = {$FileName}\r
FileUrl   = {$FileInfo['Content-Location']}\r
FileSize   = {$FileInfo['Content-Length']}";
    $handle = fopen ('Config.ini', "wb");                                                                 // Config.ini
    if (fwrite ($handle, $FileConStr) == FALSE) {                                                         //
     echo "File creation failed ...";
    }
    fclose ($handle);                                                                                     //
    $FileCon = parse_ini_file('Config.ini');
   }
   if(!empty($$this->dowUrl)){
    $fp = @fopen($$this->dowUrl, "rb");                                                                   //
    if (!$fp)
      exit("Download a mistake.

");

    //
    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);                                                                                 //
     echo fread($fp, 1024);                                                                             //
     flush();                                                                                           //
     ob_flush();                                                                                        //
    }
    fclose($fp);
   }else{
    header("HTTP/1.1 404 Not Found");
   }
  }else{
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: ".$this->Location);
  }
 }
}
//
$dowUrl = 'http://dldir1.qq.com/qqfile/qq/QQ5.1/10055/QQ5.1.exe';
//
$Location = 'http://jb51.net';
//
$allowUrl = array(
 'jb51.net',
);
$BurglarDow = new BurglarDow($dowUrl,$Location,$allowUrl);
$BurglarDow -> dow();