To get the remote file using the PHP curl, the code is as follows:
Copy the Code code 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_followlocation,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;
?>
Generally in Win2003+iis under the example, the Php_curl.dll configuration is OK.
But the author in Linux+apahe2.0+php5.2.12+directadmin, (General foreign host is used this configuration) if the URL gets 301/302 jump, will error:
curl_setopt () [function.curl-setopt]: curlopt_followlocation cannot be activated when in Safe_mode or a open_basedir is s ET in * * *
On this issue, Google, Baidu, are in the big article long Chinese, not proficient in Linux is really headache.
The solution is really simple: log in to your directadmin
Find->> "PHP safemode Configuration"-->> see
With the default Safe and Defaults Open BaseDir off, the problem is solved.
The above describes the CMOS checksum error-defaults l about PHP curl to get 301 or 302 of the URL problem of the solution, including the CMOS checksum error-defaults L aspects of the content, You want to be helpful to a friend who is interested in PHP tutorials.