CURL error (CURLOPT_FOLLOWLOCATION cannot be activated)

Warning: curl_setopt () [Function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or open_basedir is set to /home/path/curl.php on line 594

I do not have access to php.ini. Can this be fixed without editing php.ini?

+5
source share
3 answers

See this comment in the manual. This provides an ugly workaround. I believe that this restriction is due to an error in the curl library where it will follow redirects to local resources, but this should be fixed by now, so I see no reason for this restriction.

+3

safe_mode PHP_INI_SYSTEM - , , , php.ini vhost.

open_basedir PHP_INI_ALL, .htaccess php_value.

0

It works for me!

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

All Articles