卷曲关注位置无法在服务器上运行

时间:2013-05-03 15:14:59

标签: php curl

我有一个脚本,在我的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);

2 个答案:

答案 0 :(得分:1)

某些服务器检查是否存在某些标头 可能遗漏Accept-Language

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

referer

curl_setopt($ch, CURLOPT_REFERER, $dir_url);

答案 1 :(得分:1)

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

我使用了这篇博文的功能:

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

现在正在工作!