在共享主机上收到错误。在本地主机和VPS与数字海洋上工作正常。错误是:
Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in
/var/www/vhosts/qbf.ie/subdomains/projects/httpdocs/smartquotes/wp-
content/themes/smartquotes/form/functions.php on line 59
ERROR: cURL response is empty!
我的代码在functions.php中抛出错误
function send_xml_phi($xml) {
$url = 'http://www.xxx.ie/interface_phi.php';
$ch = curl_init();
if(!$ch) {
die('ERROR: cURL initialization failed!');
}
$redirects = 0;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "xml=".urlencode($xml));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$xml_result=curl_exec_follow($ch,$redirects);
curl_close($ch);
if(!$xml_result) {
die('ERROR: cURL response is empty!');
}
$xml = simplexml_load_string($xml_result, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
return $array['Outputs'];
}
这里是result.php代码foreach循环:
foreach($output['Quotes']['Type']['Company'] as $key => $company) {
if($company['SLevel'] != '-' && $company['SLevel'] < $min) {
$min = $company['SLevel'];
$min_key = $key;
}
if($company['SMortgage'] != '-' && $company['SMortgage'] < $min) {
$min = $company['SMortgage'];
$min_key = $key;
}
}
if($min_key > -1) {
$text .= '<strong>Cheapest quote:</strong> '.$min.' EUR';
$text .= ' ('.$output['Quotes']['Type']['Company'][$min_key]['Name'].')<br />';
}
有一些解决方法吗?
答案 0 :(得分:0)
CURLOPT_FOLLOWLOCATION可能隐含了安全问题,而php.ini安全指令 open_basedir 正在阻止使用CURLOPT_FOLLOWLOCATION。因此,您可以选择在没有CURLOPT_FOLLOWLOCATION的情况下使用cURL或在php.ini配置文件中取消设置 open_basedir 。