When using php's curl to obtain remote files, the code is as follows:
Copy the code The code is as follows:
$ghurl = isset($_GET['id']) ? $_GET['id' ]:'http://www.baidu.com/';
// php get
function getContents($url){
$header = array("Referer: http://www.baidu.com/");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_FO LLOWLOCATION ,1); //Whether to crawl the page after the jump
ob_start();
curl_exec($ch);
$contents = ob_get_contents();
ob_end_clean();
curl_close($ch);
return $contents ;
}
$contents = getContents($ghurl);
echo $contents;
?>
Change the default Default Safe and Default Open BaseDir OFF, the problem is solved.
The above introduces the cmos checksum error-defaults l solution to the problem of php curl obtaining 301 or 302 redirected URLs, including cmos checksum error-defaults l. I hope it will be helpful to friends who are interested in PHP tutorials.