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条)

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?