Reputation: 689
I have a script which is working fine on my xampp and deals with the follow location just fine.
But now I have transferred it to the server and it doesn't work. I'm just receiving the 301 moved permanently
site. My cUrl looks like this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_URL, $dir_url);
I have tried it with error reporting on:
error_reporting(E_ALL);
But it just doesn't output any errors...
Any ideas what it could be?
Edit:
//Start Curl Connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_URL, $dir_url);
//read content of $url
$result = curl_exec ($ch);
echo curl_error ($ch);
curl_close ($ch);
Upvotes: 0
Views: 4028
Reputation: 689
I think the problem was, that a open_basedir is set in the PHP settings.
I used the function from this blog post:
http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/
Now its working!
Upvotes: 1
Reputation: 3549
Some servers check for the existence of certain headers.
Probably Accept-Language
is missing:
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept-Language: en-us'
));
Or the referer
:
curl_setopt($ch, CURLOPT_REFERER, $dir_url);
Upvotes: 1