我正在使用cURL構建基本鏈接檢查器。我的應用程序有一個名爲getHeaders()函數返回的HTTP標頭的數組:與mail.google.com,cURL和http://validator.w3.org/checklink混淆
function getHeaders($url) { if(function_exists('curl_init')) { // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options $options = array( CURLOPT_URL => $url, CURLOPT_HEADER => true, CURLOPT_NOBODY => true, CURLOPT_FOLLOWLOCATION => 1, CURLOPT_RETURNTRANSFER => true); curl_setopt_array($ch, $options); // grab URL and pass it to the browser curl_exec($ch); $headers = curl_getinfo($ch); // close cURL resource, and free up system resources curl_close($ch); } else { echo "Error: cURL is not installed on the web server. Unable to continue.
"; return false; } return $headers; } print_r(getHeaders('mail.google.com'));
其產生以下結果:
Array ( [url] => http://mail.google.com [content_type] => text/html; charset=UTF-8 [http_code] => 404 [header_size] => 338 [request_size] => 55 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.128 [namelookup_time] => 0.042 [connect_time] => 0.095 [pretransfer_time] => 0.097 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0.128 [redirect_time] => 0 )
我和幾個長期的聯繫進行了測試,並且功能承認重定向,除了mail.google.com似乎。
爲了好玩,我通過相同的URL(mail.google.com)W3C的鏈接檢查,這就產生:
Results Links Valid links! List of redirects The links below are not broken, but the document does not use the exact URL, and the links were redirected. It may be a good idea to link to the final location, for the sake of speed. warning Line: 1 http://mail.google.com/mail/ redirected to https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=zpwhtygjntrz&scc=1<mpl=default<mplcache=2 Status: 302 -> 200 OK This is a temporary redirect. Update the link if you believe it makes sense, or leave it as is. Anchors Found 0 anchors. Checked 1 document in 4.50 seconds.
哪個是正確的,因爲上面的地址是哪裏,我重定向到何時我在我的瀏覽器中輸入mail.google.com。
我需要使用哪些cURL選項才能使mail.google.com的函數返回200?
爲什麼上面的函數返回404狀態碼而不是302狀態碼?
TIA