/** +----------------------------------------------------------* 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