我想PHP的get_headers不允許上下文,所以我不得不改變默認的流上下文來獲取請求的HEAD。這會導致頁面上其他請求發生一些問題。我似乎無法弄清楚如何重置默認流上下文。我正在嘗試類似於:PHP:get_headers設置臨時stream_context
$default = stream_context_get_default(); //Get default stream context so we can reset it
stream_context_set_default(//Only fetch the HEAD
array(
'http' => array(
'method' => 'HEAD'
)
)
);
$headers = get_headers($url, 1); //Url can be whatever you want it to be
//var_dump($headers);
var_dump($default);
stream_context_set_default($default); //This doesn't work as it expects an array and not a resource pointer
有沒有人知道此問題的解決方法?
我知道有人建議使用Curl,但我寧願不要這個。謝謝!
get_headers不一致:http://stackoverflow.com/questions/12781795/get-headers-inconsistency – Baba