PHP Curl Get 301/302 Jump file Error Problem resolution

Source: Internet
Author: User

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.