duancenxie2233 2010-11-18 20:38
浏览 17
已采纳

cURL无法正常工作!

I have a question about cURL. I am using cURL with this function:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Only this was causing an error: "Message: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set"

So I asked my hosting provider to fix this, and they did. But, and this is really stupid, they put a "curl" file in my bin directory. And I have no idea how to include this in my php script :S.

Never done it before, but can anybody help me. I am really stuck. I hope I posted enough info!

Tnx in advanced!


Tnx for all the great replies. But How would I fit "exec()" in this code?

    // create a new cURL resource
    $ch = curl_init();

    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_TRANSFERTEXT, TRUE);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_URL, $articleUrl);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_MAXREDIRS, 5);

    // grab URL and pass it to $grabArticle
    $grabArticle = curl_exec($ch);

Edit 2: Oké, I almost got it working :). It is working just fine when I run it in putty, but in my php script nothing happens :(

I run this:

$grabArticle = exec('/home/twittern/bin/curl -L -m 30 -w url_effective --max-redirs 5 http://fok.nl/415758');
echo $grabArticle;

Any thing I am doing wrong?

  • 写回答

3条回答 默认 最新

  • dongxu1029 2010-11-18 20:44
    关注

    Instead of using the built-in cURL functions within PHP, they are asking you to use the external command-line version.

    Use the PHP exec() function to call the program, the command line options can be found on the curl man page.

    Given that you probably need the response in full, you may need to use passthru() with output buffering or save the output to a (temporary) file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改