延迟将POST请求重定向到另一个页面

时间:2014-12-24 09:25:04

标签: php

我在重定向到其他页面时发现错误。这是我的代码:

payment.php:

<form action="payment2.php" method="post">
<input type="hidden" name="amount" value="<?php echo $payable; ?>" />
<input type="hidden" name="confirm" value="<?php echo $confirmation; ?>" />

payment2.php:

header("Refresh: 2;url=paymentGate.php"); 
$pay=$_POST['amount1'];
$confirmation=$_POST['confirm1'];

<html>
    <head>
        <title>Redirects</title>
        <meta http-equiv="refresh" content="2; URL=paymentGate.php" />
        <script type="text/javascript">
                    window.setTimeout(function() {
                        location.href = 'paymentGate.php';
                    }, 2000);
        </script>

          <input  type="hidden" name="amount1" value="<?php echo $pay; ?>" />
        <input   type="hidden" name="confirm1" value="<?php echo $confirmation; ?>" />
    </head>
    <body>

paymentGate.php:

$pay=$_POST['amount1'];
$confirmation=$_POST['confirm1'];

echo <?php $pay ?>
echo <?php $confirmation ?>

amount1和confirm1是paymentGate.PHP中未定义的索引。如何解决这个问题?

4 个答案:

答案 0 :(得分:1)

重定向不会神奇地重新提交表单。尝试这样的事情:

<form action="paymentGate.php" method="post" id="myForm">
     <input type="hidden" name="amount1" value="<?php echo $pay; ?>" />
     <input type="hidden" name="confirm1" value="<?php echo $confirmation; ?>" />
</form>
<script>
   setTimeout(function() { document.getElementById('myForm').submit() }, 2000);
</script>

这将自动提交“假冒”&#39;在2秒内形成。

答案 1 :(得分:0)

你不能重新定位帖子数据maby be you shold try get menthod

 window.location = '/paymentGate.php?amount1='+amount1&confirm1='+confirm1;

答案 2 :(得分:0)

2秒后制作表格。这样就可以了。

$pay=$_POST['amount1'];
$confirmation=$_POST['confirm1'];

<html>
    <head>
        <title>Redirects</title>
        <script type="text/javascript">
                    window.setTimeout(function() {
                        document.form1.submit();
                    }, 2000);
        </script>

</head>
    <body>
<form method="post" action="paymentGate.php" name="form1" id="form1">
          <input  type="hidden" name="amount1" value="<?php echo $pay; ?>" />
        <input   type="hidden" name="confirm1" value="<?php echo $confirmation; ?>" />
</form> 
</body>
</html>

答案 3 :(得分:-1)

$pay=$_POST['amount1'];
$confirmation=$_POST['confirm1'];

sleep(5) //5 seconds

echo <?php $pay ?>
echo <?php $confirmation ?>