php curl with CURLOPT_FOLLOWLOCATION error
The error means safe_mode or open_basedir ARE enabled (probably open_basedir) you probably can't override either if your host has any decent security settings.
So you have a choice
1) change host (not really desirable I imagine)
2) use a function similar to ones found on the php curl_setopt page, i.e. http://www.php.net/manual/en/function.curl-setopt.php#95027
The following is a fixed version of the function specified in point 2
function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) {
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302) {
list($header) = explode("\r\n\r\n", $data, 2);
$matches = array();
preg_match("/(Location:|URI:)[^(\n)]*/", $header, $matches);
$url = trim(str_replace($matches[1], "", $matches[0]));
$url_parsed = parse_url($url);
if (isset($url_parsed)) {
curl_setopt($ch, CURLOPT_URL, $url);
$redirects++;
return curl_redirect_exec($ch, $redirects, $curlopt_header);
}
}
if ($curlopt_header) {
return $data;
} else {
list(, $body) = explode("\r\n\r\n", $data, 2);
return $body;
}
}
CURL error (CURLOPT_FOLLOWLOCATION cannot be activated)
See this comment in the manual. It provides an ugly workaround. I believe this restriction is effect because of a bug in the curl library where it would follow redirects to local resources, but that should be fixed by now, so I see no reason for this restriction.
CURLOPT_FOLLOWLOCATION cannot be activated
Set safe_mode = Off
in your php.ini file (it's usually in /etc/ on the server). If that's already off, then look around for the open_basedir
stuff in the php.ini file, and change it accordingly.
Basically, the follow location option has been disabled as a security measure, but PHP's built-in security features are usually more annoying than secure. In fact, safe_mode
is deprecated in PHP 5.3.
cURL Error when using CURLOPT_FOLLOWLOCATION
This is because your setup has either safe mode or open_basedir settings in the php.ini.
You need to change these settings in the php.ini to do this.
Related Topics
How to Convert a Single Array into a Multidimensional Array in PHP
Check If Username Exists in MySQL Table via PHP
How to Read the Query String in PHP and HTML
Adding User Custom Field Value to Order Items Details
How to Check If User Has Already Liked the Facebook Page
PHP Post Limited to 1000 Variables
Wherejsoncontains Laravel 5.6 Not Working
Firefox Error 'No Element Found'
Error Tolerant HTML/Xml/Sgml Parsing in PHP
Printing PHP Script Output to File
How to Display Images from a Folder Using PHP - PHP
PHP Associative Array Key Order (Not Sort)
Class App\Http\Controllers\Usercontroller Does Not Exist
Count All Child Nodes of Hierarchical Data in a Table