Home >Backend Development >PHP Tutorial >PHP collection code-anti-hotlink collection_PHP tutorial

PHP collection code-anti-hotlink collection_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:06:141062browse

Many PHP novices will directly use file_get_contents to read or fopen when developing their own website collection function, right? Our download collection function has been strengthened a little bit to prevent the other party's anti-leeching function from being able to prevent it.

Many PHP novices will directly use file_get_contents to read or fopen when developing their own website collection function, right? Our download collection function has been strengthened a little bit, so that the other party's anti-leeching cannot prevent the collection. Function.

function retrieveURLContentBySocket($url,
$port=80,
                                                                                                                                                         {
if(!($pos = strpos($url,'://'))){
return false;
}
$host = substr( $url,
$ pos+3,
                                                                                                                                           strpos($url,'/',$pos+3) - $pos - 3); +3));
}
else{
$uri = $url;
}

$request = "GET ".$uri." HTTP/1.0rn"
."Host: ".$host."rn"

."Accept: */*rn"

."User-Agent: ZealGetrn"
."rn ";
$sHnd = @fsockopen ($host, $port, $errno, $errstr, $timeout);
if(!$sHnd){
return false;
}


@ fputs ($sHnd, $request);

// Get source
$result = "";

while (!feof($sHnd)){

$result .= fgets( $sHnd,4096);
}
fclose($sHnd);

$headerend = strpos($result,"rnrn");
if (is_bool($headerend))

{

return $result;
}
else{
return substr($result,$headerend+4);
}



http://www.bkjia.com/PHPjc/445057.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445057.htmlTechArticleMany PHP newbies will directly use file_get_contents to read or fopen when developing their own website collection functions, right? Right, our download and collection function has been strengthened a little bit just to ask the other party...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn