Error: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set

0
=
0
+
0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

If you have a cURL script that tries to use CURLOPT_FOLLOWLOCATION you might get the following error:

Warning: curlsetopt() [function.curl-setopt]: CURLOPTFOLLOWLOCATION cannot be activated when in safemode or an openbasedir is set in /home/username/public_html/path/to/script.php on line xxx

open_basedir is enabled on all shared servers as it is essential to proper server security. The vast majority of the time a programmer will set this option to true in their script even when it's not needed.

Your file might have an entry similar to this

function connect($data,$api_url)
{
$data = http_build_query($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $api_url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$conn = array('result'=>$result,'info'=>$info);
return $conn;
}

To fix the error all you need to do is open that script in the cPanel file manager using the script editor. Find the line number mentioned in the error message. It should have "FOLLOWLOCATION" in it. Delete it or comment it out and it should get your script working again. This would be a working example of the above script

function connect($data,$api_url)
{
$data = http_build_query($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $api_url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$conn = array('result'=>$result,'info'=>$info);
return $conn;
}
Tags: ,
User rating:

Thanks

0 answers

0
=
0
=
$0
Internet users could send Bitcoin Tips to you if they like your answer!

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer