【问题标题】:Send multiple headers or multiple submitting for the form?为表单发送多个标题或多次提交?
【发布时间】:2019-10-02 19:56:49
【问题描述】:

当用户插入两个数字(from-to)时,我想为每个数字发送(((完整路径)))。 我将如何做到这一点? PHP,javascript或任何其他语言有没有办法。我会为表单发送多个标题或多次提交吗?

附注:
单独接收和处理每个数字的 (go.php) 页面。我无法对其进行更改,我只需将单个数字发送给它,因为这就是其他页面的编码方式。

这是我尝试过的:

<form action="test.php" method="post">
<input type="text" name="first">
<input type="text" name="second">
<input type="submit" name="submit">
</form>

<?php
$f=$_POST['first'];
$s=$_POST['second'];
for($i=$f; $i<=$s; $i++){
header('location:go.php?f='.$i);
}
?>

【问题讨论】:

  • 它显示的错误是什么?
  • 它只发送带有最后一个数字的最后一个标头
  • 实际上 PHP 标头函数不允许发送多个标头函数。发生的情况是,它会覆盖最新的值。所以我认为这就是你重定向到最后一个号码的原因。
  • 是的,我知道,有没有办法为每个发送完整路径:(
  • 你真正想要达到什么目的?将人们重定向数百次是没有意义的。

标签: javascript php jquery html ajax


【解决方案1】:

你不能两次发送标题,你可以像下面这样做

<?php
$f=$_POST['first'];
$s=$_POST['second'];
header('location:go.php?first='.$i.'&second='.$s);
?>

go.php

您可以使用 get 方法捕获这两个变量

<?php
    $first=$_GET['first'];
    $second=$_GET['second'];

    //rest of the code
 ?>

【讨论】:

    【解决方案2】:

    为什么不用javascript提交这么多次:

    // supposing you have jQuery
    for (var i = Number($(':input[name=first]').val()),
           end = Number($(':input[name=second]').val()); 
             i <= end; i++) {
        $.get('go.php', { f: i }, function (response){ 
             // do something with response
        });
    }
    

    【讨论】:

      【解决方案3】:

      你不能通过简单的单一脚本来做到这一点。您可以通过多线程或 curl 来实现。我给你举个 curl 的例子:

      一个.php

      <form action="test.php" method="post">
      <input type="text" name="first">
      <input type="text" name="second">
      <input type="submit" name="submit">
      </form>
      
      <?php
      $f=$_POST['first'];
      $s=$_POST['second'];
      for($i=$f; $i<=$s; $i++){
        //write curl code to execute two.php with url : http:// yoursite.com/two.php?f=$i
      }
      ?>
      

      两个.php

      <?php
          header('location:go.php?f='.$_REQEST['f']);
      ?>
      

      希望这个解释对你有所帮助。祝你好运。

      【讨论】:

        猜你喜欢
        • 2015-08-10
        • 1970-01-01
        • 2017-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多