首頁 > 後端開發 > php教程 > 一段phpcurl代码,phpcurl代码_PHP教程

一段phpcurl代码,phpcurl代码_PHP教程

WBOY
發布: 2016-07-12 09:05:20
原創
1101 人瀏覽過

一段phpcurl代码,phpcurl代码

    <span>$header</span>[] = 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, text/html, * ' . '/* '<span>;
    </span><span>$header</span>[] = 'Accept-Language: zh-cn '<span>;
    </span><span>$header</span>[] = "User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"<span>;

    </span><span>$ch</span> = curl_init(); <span>//</span><span>初始化curl

        //允许curl提交后,网页重定向</span>
    curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, 1<span>);
    curl_setopt(</span><span>$ch</span>, CURLOPT_FOLLOWLOCATION, 1<span>);

    </span><span>//</span><span>将curl提交后的header返回</span>
    curl_setopt(<span>$ch</span>, CURLOPT_HEADER, 1<span>);
     </span><span>//</span><span>递归抓取LOCATION</span>
    curl_setopt(<span>$ch</span>, CURLOPT_FOLLOWLOCATION, 1<span>);     
    
    </span><span>//</span><span>以上处理重定向</span>
<span>
    curl_setopt(</span><span>$ch</span>, CURLOPT_URL, <span>$url</span>); <span>//</span><span>设置链接</span>
    curl_setopt(<span>$ch</span>, CURLOPT_SSL_VERIFYPEER, <span>FALSE</span>); <span>//</span><span>HTTPS必须设置不验证</span>
    curl_setopt(<span>$ch</span>, CURLOPT_SSL_VERIFYHOST, <span>FALSE</span>); <span>//</span><span>HTTPS必须设置不验证</span>
    curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>TRUE</span>); <span>//</span><span>设置是否返回信息</span>
    curl_setopt(<span>$ch</span>, CURLOPT_HTTPHEADER,     <span>$header</span>); <span>//</span><span>设置HTTP头</span>

    <span>$html</span> = curl_exec(<span>$ch</span>); <span>//</span><span>接收返回信息</span>
<span>
    curl_close(</span><span>$ch</span>);
登入後複製

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1069126.htmlTechArticle一段phpcurl代码,phpcurl代码 $header [] = 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, text/html, * ' . '/* ' ; $header [] =...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板