dtja73027 2011-06-23 10:01
浏览 68
已采纳

我怎么循环$ _POST

My current host doesn't allow remote mysql acces so I need to work around it by having script1 on server1 communicate with script2 on server2. I am trying to send post data to script2, which then takes that data and puts it into mysql. To keep my question simple I stripped the code down to this:

script1

for ( $counter = $counternumbernao; $counter <= $amountofcomments; $counter += 1) 
{
echo'
<form action="http://server2.x.com/form-receive.php" method="post">
<INPUT TYPE=HIDDEN NAME="comment_content" value=$comment_content>
<INPUT TYPE=HIDDEN NAME="comment_date" value=$comment_date">
<input type="submit" />
</form>
';
}

How can I alter this code, so that every time the loop occurs it automatically sends the $_POST data to script2, which then puts it into mysql? I didn't think it was necessary to include script2 as it's not important to this issue.

  • 写回答

5条回答 默认 最新

  • doukuang1897 2011-06-23 10:09
    关注

    To have this automatically occur without the end user being aware of this behaviour, the best way would be to use CURL (http://php.net/manual/en/book.curl.php).

    Here's an example of how it would look:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://server2.x.com/form-receive.php");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    
    $data = array(
        'foo' => 'bar',
        // Put data from $_POST here
    );
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分