Home > Backend Development > PHP Tutorial > cmos checksum error-defaults l Solution to the problem of php curl obtaining the URL redirected by 301 or 302

cmos checksum error-defaults l Solution to the problem of php curl obtaining the URL redirected by 301 or 302

WBOY
Release: 2016-07-29 08:45:20
Original
1076 people have browsed it

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;
?>


Generally speaking, under win2003+iis, if php_curl.dll is configured, there will be no problem.
But the author is using linux+apahe2.0+php5.2.12+directadmin (generally foreign hosting providers use this configuration). If the obtained URL has a 301/302 jump, an error will be reported:
curl_setopt() [function.curl-setopt ]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in ***
About this issue, Google and Baidu, they are all in long English, which is really a headache for those who are not proficient in Linux.
The solution is actually very simple: Log in to your directadmin
Find->>"PHP SafeMode Configuration" -->>Look at the picture below

 关于php curl获取301或302转向的网址问题的解决方法

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template