因此,我在多个服务器上不断收到这个恼人的错误(这是一个警告,所以我会忽略它,但我需要这个函数)
警告: curl_setopt()函数。html setopt:如果启用了CURLOPT_FOLLOWLOCATION或在/home/xxx/public_html/xxx.php第56行设置了safe_mode,则无法激活open_basedir
我该如何通过SSH修复这个问题呢?
发布于 2011-08-03 05:13:25
在php.ini文件中设置safe_mode = Off
(它通常位于服务器上的/etc/中)。如果这已经关闭,那么在php.ini文件中查找open_basedir
内容,并对其进行相应的更改。
基本上,作为一种安全措施,跟随位置选项已被禁用,但PHP的内置安全特性通常更令人讨厌,而不是安全。事实上,safe_mode
is deprecated in PHP 5.3。
发布于 2011-08-03 05:18:23
尝试这个,如果重定向是必需的,并且安全模式被启用,它将遵循基于标题的链接(如果您的抓取图像虽然这将不会工作,因为它添加标题到返回),这是您的特定问题的变通办法,当客户安装我的脚本之一时,我有相同的问题,所以必须拿出这个。它还会将错误记录到:curl.error.log
..有用吗?
<?php
function geturl($url) {
(function_exists('curl_init')) ? '' : die('cURL Must be installed for geturl function to work. Ask your host to enable it or uncomment extension=php_curl.dll in php.ini');
$curl = curl_init();
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Firefox/5.0');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); //CURLOPT_FOLLOWLOCATION Disabled...
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
$html = curl_exec($curl);
$status = curl_getinfo($curl);
curl_close($curl);
if ($status['http_code'] != 200) {
if ($status['http_code'] == 301 || $status['http_code'] == 302) {
list($header) = explode("\r\n\r\n", $html, 2);
$matches = array();
preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
$url = trim(str_replace($matches[1],"",$matches[0]));
$url_parsed = parse_url($url);
return isset($url_parsed) ? geturl($url) : '';
}
$oline='';
foreach ($status as $key => $eline) {
$oline .= '['.$key.']'.$eline.' ';
}
$line = $oline." \r\n ".$url."\r\n-----------------\r\n";
$handle = @fopen('./curl.error.log', 'a');
fwrite($handle, $line);
return false;
}
return $html;
}
发布于 2011-08-03 05:17:16
https://stackoverflow.com/questions/6918623
复制相似问题