drmqzb5063 2013-04-03 00:11
浏览 14
已采纳

使用PHP cURL发布数据

If there are 2 form fields in a page with 2 different submit buttons how do I tell to cURL which form to submit?

Example

<form method="post" action="index.php">
   <input type="text" name="age">
   <input type="submit" name="agree">
   <input type="submit" name="disagree">
</form>

My code so far

//create array of data to be posted
$post_data['age'] = '5';
 
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

$post_string = implode ('&', $post_items);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
  • 写回答

2条回答 默认 最新

  • dtlygweb2017 2013-04-03 00:31
    关注

    There is no needing to know which form in HTML must be posted.

    Form can be determined by Method, Action and/or Set of fields.

    P.S. Clicked named submits are sending too. So add post_data['agree'] = '';.

    P.P.S. Don not use it for spam.

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

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办