標籤:函數 function ati 大小 oca top header cat 請求
//php curl get擷取head頭部跳轉參數 function get_head($sUrl){ $oCurl = curl_init();// 佈建要求頭, 有時候需要,有時候不用,看請求網址是否有對應的要求 $header[] = "Content-type: application/x-www-form-urlencoded"; $user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"; curl_setopt($oCurl, CURLOPT_URL, $sUrl); curl_setopt($oCurl, CURLOPT_HTTPHEADER,$header);// 返回 response_header, 該選項非常重要,如果不為 true, 只會獲得響應的本文 curl_setopt($oCurl, CURLOPT_HEADER, true);// 是否不需要響應的本文,為了節省頻寬及時間,在只需要回應標頭的情況下可以不要本文 curl_setopt($oCurl, CURLOPT_NOBODY, true);// 使用上面定義的 ua curl_setopt($oCurl, CURLOPT_USERAGENT,$user_agent); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );// 不用 POST 方式請求, 意思就是通過 GET 請求 curl_setopt($oCurl, CURLOPT_POST, false); $sContent = curl_exec($oCurl);// 獲得響應結果裡的:頭大小 $headerSize = curl_getinfo($oCurl, CURLINFO_HEADER_SIZE);// 根據頭大小去擷取頭資訊內容 $header = substr($sContent, 0, $headerSize); curl_close($oCurl); $headArr = explode("\r\n", $header); foreach ($headArr as $loop) { if(strpos($loop, "Location") !== false){ $edengUrl = trim(substr($loop, 10)); } } return $edengUrl; }
php常用函數