PHP的卷曲与CURLOPT_FOLLOWLOCATION错误
我得到一个错误PHP的卷曲与CURLOPT_FOLLOWLOCATION错误
CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in
我谷歌很多的解决方案,但这个网站他们不工作。只需要CURLOPT_FOLLOWLOCATION。愚蠢的主机不想启用safe_mode或open_basedir。我可以自己启用它们,可以使用一些参数创建htaccess吗?
错误意味着safe_mode或open_basedir启用(可能是open_basedir)如果您的主机有任何体面的安全设置,则您可能无法重写该错误。
所以,你有一个选择
1)改变主机(不是真的希望我想象)
2)使用类似PHP curl_setopt页面上找到那些函数,即http://www.php.net/manual/en/function.curl-setopt.php#95027
的以下是第2点中
function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) {
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302) {
list($header) = explode("\r\n\r\n", $data, 2);
$matches = array();
preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
$url = trim(str_replace($matches[1], "", $matches[0]));
$url_parsed = parse_url($url);
if (isset($url_parsed)) {
curl_setopt($ch, CURLOPT_URL, $url);
$redirects++;
return curl_redirect_exec($ch, $redirects, $curlopt_header);
}
}
if ($curlopt_header) {
return $data;
} else {
list(, $body) = explode("\r\n\r\n", $data, 2);
return $body;
}
}
您好我修理添加此条件中指定的功能的一个固定的版本:
$safeMode = @ini_get('safe_mode');
$openBasedir = @ini_get('open_basedir');
if (empty($safeMode) && empty($openBasedir)) {
curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
}else
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
,并加入我的.htaccess文件
php_flag safe_mode off
php_flag open_basedir off
你的$ curl和$ curl_handle变量来自哪里? – Craig 2015-02-10 20:14:47
有趣,但脚本在我的主机上运行良好(廉价和虚拟),但老板使用愚蠢的主机,并没有改变的愿望。关于这个功能 - 我知道它,当我开始写脚本我手动调用每个url,但最后一个url不会不会工作,只有使用CURLOPT_FOLLOWLOCATION帮助我 – kusanagi 2010-10-08 13:25:37
Eek对不起,我没有实际测试函数,重新对它不起作用(它假设位置标题不是最后一个)我已经添加了一个我测试过的修正版本给我的答案。 – Rwky 2010-10-08 17:31:08
您的解决方案有一些错误。正则表达式应该是'[^ \ n]'。当递归调用'curl_redirect_exec'时,你应该传递'$ curlopt_header'。 – 2011-11-01 22:16:15