Heim  >  Artikel  >  Backend-Entwicklung  >  php采集代码-反防盗链采集_PHP教程

php采集代码-反防盗链采集_PHP教程

WBOY
WBOYOriginal
2016-07-20 11:06:141003Durchsuche

很多php新手在开发自己的网站采集功能时都会直接用到file_get_contents来读取或fopen是吧,是吧,我们下载采集功能加强了了一点点就是要对方的防盗链都不能防止的采集功能。

很多php新手在开发自己的网站采集功能时都会直接用到file_get_contents来读取或fopen是吧,是吧,我们下载采集功能加强了了一点点就是要对方的防盗链都不能防止的采集功能。

function retrieveURLContentBySocket($url,
                                    $host="",
                                    $port=80,
                                    $timeout=30){
    if($host == ""){
        if(!($pos = strpos($url,'://'))){
            return false;
        }
        $host = substr( $url,
                        $pos+3,
                        strpos($url,'/',$pos+3) - $pos - 3);
        $uri = substr($url,strpos($url,'/',$pos+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);
    }


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445057.htmlTechArticle很多php新手在开发自己的网站采集功能时都会直接用到file_get_contents来读取或fopen是吧,是吧,我们下载采集功能加强了了一点点就是要对方...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn