PHP Funciton Mycurl

Source: Internet
Author: User

/** +----------------------------------------------------------* CURL +------------------------------------------- ---------------* @param string$url requested URL * @param string|array$post post data * @param string|array$cookie cookie Data * @par Am String$cookiefile record the file name of the cookie * @param string$referer source page +------------------------------------------------------ ----* @return string +----------------------------------------------------------*/function mycurl ($url, $post = ", $    Cookie= ', $cookieFile = ', $referer = ') {$curl = Curl_init (); $userAgent = ' mozilla/5.0 (Windows NT 6.1; WOW64;    rv:8.0) gecko/20100101 firefox/8.0 ';    $userAgent = Empty ($userAgent)? $_server[' Http_user_agent ']: $userAgent;    curl_setopt ($curl, Curlopt_url, $url); curl_setopt ($curl, Curlopt_timeout, 5);//curl the maximum number of seconds allowed to execute curl_setopt ($curl, Curlopt_header, 0);//Outputs the header file information as a data stream curl_s  Etopt ($curl, Curlopt_returntransfer, 1);//true is returned as a file stream;    False direct output;  curl_setopt ($curl, curlopt_followlocation, 0);//whether to get redirected information  curl_setopt ($curl, Curlopt_maxredirs, 5);//redirect Maximum number of times curl_setopt ($curl, curlopt_useragent, $userAgent);//    HTTP request in User-agent: "section of Content if ($referer) {curl_setopt ($curl, Curlopt_referer, $referer);    }else{curl_setopt ($curl, Curlopt_autoreferer, 1);    } if ($post) {curl_setopt ($curl, Curlopt_post, 1);    curl_setopt ($curl, Curlopt_postfields, $post); } if ($cookieFile) {$cookieFile = DirName (__file__).    Directory_separator. $cookieFile; curl_setopt ($curl, Curlopt_cookiefile, $cookieFile);//file name with cookie data curl_setopt ($curl, Curlopt_cookiejar, $ Cookiefile);//file where cookie information is saved after connection ends} if ($cookie) {curl_setopt ($curl, Curlopt_cookie, $cookie);//http Request "Cookie:" section    Content} $result = Curl_exec ($curl); if (Curl_errno ($curl)) echo ' <pre><b>error:</b><br/> '. Curl_error ($curl). '    </pre> ';    Curl_close ($curl); return $result;}



PHP Funciton Mycurl

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.