当curl_get_contents出现failed to open stream: HTTP request failed! HTTP/1.1 403错误时,我们可以使用以下函数替代:
function curl_get_contents($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); $html = curl_exec($ch); $data = curl_exec($ch); curl_close($ch); return $data; }