Class usualfunfornetworkhelper{/*** * POST request data */public static function httpspost ($url, $data = null, $hea DERs = Null) {$curl = Curl_init (); curl_setopt ($curl, curlopt_url, $url); curl_setopt ($curl, curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, curlopt_ssl_verifyhost, FALSE); If (!empty ($data)) {curl_setopt ($curl, curlopt_post, 1); curl_setopt ($curl, curlopt_postfields, $data); } curl_setopt ($curl, curlopt_returntransfer, 1); $output = curl_exec ($curl); Curl_close ($curl); Header ("content-type:text/html; Charset=utf-8 "); Return $output; /*** * HTTP Get access method */public static function HttpGet ($url, $headers = Null) {$curl = Curl_init (); curl_setopt ($curl, curlopt_url, $url); curl_setopt ($curl, curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, curlopt_ssl_verifyhost, FALSE); curl_setopt ($curl, Curlopt_useragenT, $_server[' http_user_agent '); Simulates user-used browser curl_setopt ($curl, curlopt_followlocation, 1); Use automatic jump curl_setopt ($curl, curlopt_autoreferer, 1); Auto set referer curl_setopt ($curl, curlopt_timeout, 30); Set timeout limit to prevent dead loops//curl_setopt ($curl, curlopt_header, 0); Displays the contents of the returned header area curl_setopt ($curl, curlopt_returntransfer, 1); The information obtained is returned as a file stream $output = curl_exec ($curl); Echo ' ['. $output. '] '; Return $output; /** * Get Pictures * @param $url * @param $content _type * @return bool|int|mixed */public static func tion httpgetimg ($url,& $content _type,& $error = ") {$content _type = '; $count = 0; $e _no = 28; While ($count < && $e _no = = = 28)//network timeout, 10 repeat requests {$curl = Curl_init (); curl_setopt ($curl, curlopt_url, $url); curl_setopt ($curl, curlopt_ssl_verifypeer, FALSE); curl_setopt ($curl, curlopt_ssl_verifyhost, FALSE); curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulates user-used browser curl_setopt ($curl, curlopt_followlocation, 1); Use automatic jump curl_setopt ($curl, curlopt_autoreferer, 1); Auto set referer curl_setopt ($curl, curlopt_timeout, 5); Set timeout limit to prevent dead loops//curl_setopt ($curl, curlopt_header, 0); Displays the contents of the returned header area curl_setopt ($curl, curlopt_returntransfer, 1); The information obtained is returned as a file stream $output = curl_exec ($curl); $content _type = Curl_getinfo ($curl, curlinfo_content_type); $e _no = Curl_errno ($curl); Curl_close ($curl); $count + +; } if ($e _no!== 0) {$error = $e _no; If ($e _no = = =) {log::write (' request picture Timeout 10 times, discard, url: '. $url); } return false; } $content _type = Strval ($content _type); $ok _type=[' application/octet-stream ', ' image/bmp ', ' image/giF ', ' image/jpeg ', ' image/png ']; If (!in_array ($content _type, $ok _type)) {return false; } return $output; }}
PHP Curl Crawl class Share