Curl followlocation在服务器上不工作


Curl followlocation not working on server

我有一个脚本,它在我的xampp上工作得很好,并处理以下位置。

但是现在我已经把它转移到服务器,它不工作。我刚收到301 moved permanently站点。我的cUrl看起来像这样:

$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);

我已经尝试了错误报告:

error_reporting(E_ALL);

但是它不输出任何错误…

你知道是什么吗?

编辑:

//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);

一些服务器检查某些头是否存在
可能缺少Accept-Language:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Accept-Language: en-us'
));

referer:

curl_setopt($ch, CURLOPT_REFERER, $dir_url);

我认为问题是,在PHP设置中设置了open_basedir。

我使用了这个博客文章中的函数:

http://slopjong.de/2012/03/31/curl-follow-locations-with-safe_mode-enabled-or-open_basedir-set/

现在它工作了!