【问题标题】:CURL error (CURLOPT_FOLLOWLOCATION cannot be activated)CURL 错误(无法激活 CURLOPT_FOLLOWLOCATION)
【发布时间】:2010-06-28 14:09:31
【问题描述】:

警告:curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION 不能 在安全模式或 open_basedir 设置在 /home/path/curl.php 第 594 行

我无权访问 php.ini。不编辑 php.ini 可以解决这个问题吗?

【问题讨论】:

    标签: curl php


    【解决方案1】:

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

    【讨论】:

    • 嗯,这肯定是一个丑陋的 hack,但它确实有效 - 基本上,您将解析响应标头并手动重定向。
    【解决方案2】:

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

    open_basedir 属于PHP_INI_ALL,因此您可以使用php_value 将其设置为.htaccess

    【讨论】:

    • 我可能弄错了,但我认为 php_admin_value 不能放在 .htaccess 文件中。也许你的意思是 php_value?
    • @Artefacto:你是正确的,固定的。 “php_admin_value (...) 这不能在 .htaccess 文件中使用。” php.net/manual/en/configuration.changes.php
    【解决方案3】:

    这对我有用!

            $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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-18
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多