CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set

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

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir 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;
	}

Was this answer helpful?

 Print this Article

Also Read

How do I install IonCube?

All of our servers have IonCube loaders installed already, you don't need to do anything.

I can't connect to my database from home

We have turned off remote MySQL access at the firewall level to increase security on the server.

How do I perform a traceroute?

From Windows, go to: Start Menu -> Click Run... -> Type in "cmd" and click OK -> When...

My site is down, Can you help?

If you can't reach your website for any reason check the following before submitting a new...

Is my site down?

If you can't reach your site, first make sure you have a connection to the internet and you can...