欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  神坛PHP

curl_init头信息

程序员文章站 2022-02-22 20:23:15
...

/**

 * [curlHtml 获取页面信息]

 * @param  [type] $url [网址]

 * @return [type]      [description]

 */


function curlHtml($url)

{

    $curl = curl_init();

    curl_setopt_array($curl, array(

        CURLOPT_URL            => "{$url}",

        CURLOPT_RETURNTRANSFER => true,

        CURLOPT_ENCODING       => "",

        CURLOPT_MAXREDIRS      => 10,

        CURLOPT_TIMEOUT        => 30,

        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,

        CURLOPT_CUSTOMREQUEST  => "GET",

        CURLOPT_HTTPHEADER     => array(


            "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",

            "Accept-Encoding: gzip, deflate, br",

            "Accept-Language: zh-CN,zh;q=0.9",

            "Cache-Control: no-cache",

            "Connection: keep-alive",

            "Pragma: no-cache",

            "Upgrade-Insecure-Requests: 1",

            "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",

            "cache-control: no-cache"


        ),

    ));

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

    $response = curl_exec($curl);

    $err = curl_error($curl);

    curl_close($curl);

    if ($err) return false;

    else return $response;

}

相关标签: curl_init 头信息