Dedicate a encapsulated curl function for easy invocation (grasping data-specific)

Source: Internet
Author: User
Tags curl
This function is to encapsulate the curl function of the common steps, convenient for everyone to grasp the data, the Thief program is similar to the code, need friends can refer to the next

Dedicate a encapsulated curl function to make it easy to call

Copy Code code as follows:


function Curl ($url, $ifpost = 0, $datafields = ', $cookiefile = ', $v = False) {


$header = Array ("Connection:keep-alive", "accept:text/html, Application/xhtml+xml, */*", "Pragma:no-cache", "Acce pt-language:zh-hans-cn,zh-hans;q=0.8,en-us;q=0.5,en;q=0.3 "," user-agent:mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; trident/6.0) ");


$ch = Curl_init ();


curl_setopt ($ch, Curlopt_url, $url);


curl_setopt ($ch, Curlopt_header, $v);


curl_setopt ($ch, Curlopt_httpheader, $header);


$ifpost && curl_setopt ($ch, Curlopt_post, $ifpost);


$ifpost && curl_setopt ($ch, Curlopt_postfields, $datafields);


curl_setopt ($ch, Curlopt_returntransfer, true);


curl_setopt ($ch, curlopt_followlocation, true);


curl_setopt ($ch, curlopt_encoding, ' gzip,deflate ');


$cookiefile && curl_setopt ($ch, Curlopt_cookiefile, $cookiefile);


$cookiefile && curl_setopt ($ch, Curlopt_cookiejar, $cookiefile);


$r = curl_exec ($ch);


curl_close ($ch);


return $r;


}



Grasping Data Special

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.