To get the remote files using PHP curl, the code is as follows:
?
$ghurl = Isset ($_get["id"])? $_get["id"]: "http://www.baidu.com/";
PHP Access
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;
?>
|
In general, under the Win2003+iis such as, the Php_curl.dll configuration is no problem.
But the author in Linux+apahe2.0+php5.2.12+directadmin, (General foreign host is using this configuration) if get the URL has 301/302 jumps, will be an error:
| curl_setopt () [function.curl-setopt]: curlopt_followlocation cannot to 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 a headache.
The solution is really simple: Log on to your directadmin
Find->> "PHP safemode Configuration"-->> look at the picture below
The default Safe and Open BaseDir are off, and the problem is solved.