Home > Article > Backend Development > PHP collection code-anti-hotlink collection_PHP tutorial
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"
."User-Agent: ZealGetrn"
."rn ";
$sHnd = @fsockopen ($host, $port, $errno, $errstr, $timeout);
if(!$sHnd){
return false;
}
@ fputs ($sHnd, $request);
// Get source
$result = "";
$result .= fgets( $sHnd,4096);
}
fclose($sHnd);
$headerend = strpos($result,"rnrn");
if (is_bool($headerend))
return $result;
}
else{
return substr($result,$headerend+4);
}