2010-06-28 52 views
5

警告:curl_setopt() [function.curl-SETOPT]: CURLOPT_FOLLOWLOCATION不能 激活safe_mode设置时或 的open_basedir在 /家/路径/卷曲设置.php on line 594CURL误差(CURLOPT_FOLLOWLOCATION不能被激活)

我没有访问php.ini的权限。这可以修改而不编辑php.ini?

回答

3

参见手册中的this comment。它提供了一个丑陋的解决方法。我相信这个限制是有效的,因为curl库中的一个bug会影响到重定向到本地资源,但是现在应该修复这个问题,所以我认为没有理由限制这个限制。

+0

那么这是一个丑陋的黑客肯定,但它的工作原理 - 基本上,你会解析响应标题和手动重定向。 – Piskvor 2010-06-28 14:19:02

0

safe_mode 0123p属于PHP_INI_SYSTEM - 所以如果这是问题,你运气不好,这些项目只能在php.ini和vhost配置中设置。

open_basedir属于PHP_INI_ALL,因此你可以使用php_value设置在.htaccess

+0

我可能会误解,但我认为php_admin_value不能放在.htaccess文件中。也许你的意思是php_value? – Artefacto 2010-06-28 14:17:52

+0

@艺术:你是对的,修好了。 “php_admin_value(...)这不能在.htaccess文件中使用。” http://php.net/manual/en/configuration.changes.php – Piskvor 2010-06-28 14:20:29

0

这是为我工作的!

 $ch = curl_init(); 

     $header=array(
      'User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0', 
      'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
      'Accept-Language: en-us,en;q=0.5', 
      'Accept-Encoding: gzip,deflate', 
      'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 
      'Keep-Alive: 115', 
      'Connection: keep-alive', 
     ); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_REFERER, $url); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.2; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //Set curl to return the data instead of printing it to the browser. 
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'curl_cookies.txt'); 
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'curl_cookies.txt'); 
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 

    $data = curl_exec($ch); 


    curl_close($ch); 

    $status = curl_getinfo($curl); 

if ($status['http_code'] == 200) { 
    return $data;  
} else { 
    echo $url; 
    return @file_get_contents($url); 
}