重定向文件不适用于PHP

时间:2015-09-26 23:40:40

标签: php redirect

我有一个非常具体的问题。我的问题是我希望人们被重定向到特定的网站,但是有一个redirect.php文件。为了重定向,我需要使用POST方法从我的html发送信息。问题是它确实将我重定向到我的主页......这是我的简化代码:

<body>
    <?php
    if (isset($_POST['submit'])) {
        ?>
        <form action="" method="POST"><button type="submit" class="btn btn-success" aria-pressed="true" name="bank1"><img src="img/cart.png"><b> Pay by bank</b></button></form></div>  
        <form action="" method="POST"><button type="submit" class="btn btn-success" aria-pressed="true" name="bank2"><img src="img/cart.png"><b> Pay by bank</b></button></form></div>
        <form action="" method="POST"><button type="submit" class="btn btn-success" aria-pressed="true" name="bank3"><img src="img/cart.png"><b> Pay by bank</b></button></form></div>
        <form action="" method="POST"><button type="submit" class="btn btn-success" aria-pressed="true" name="bank4"><img src="img/cart.png"><b> Pay by bank</b></button></form></div>
        <?php
    }
    else if ($_POST['bank1']) {
        require_once 'libwebtopay/redirect.php';
    }
    else {
        ?>
        <form action="" method="POST"><button type="submit" class="btn btn-success" aria-pressed="true" name="submit"><b>Login</b></button></form></div>
        <?php 
    }
    ?>
</body>

如果不能正常工作那么。它会将我重定向到其他{}页面。这是redirect.php简化代码:

 try { if (isset($_POST['bank1'])) {
$request = WebToPay::redirectToPayment(array(
    'projectid'     => $projectid,
    'sign_password' => $sign_pass,
    'orderid'       => $vardas,
    'amount'        => $vip1,
    'currency'      => 'EUR',
    'country'       => 'LT',
    'accepturl'     => $self_url.'/accept.php',
    'cancelurl'     => $self_url.'/cancel.php',
    'callbackurl'   => $self_url.'/callback.php',
    'test'          => 1,
)); }

尝试在每个表单下包含redirect.php文件也无济于事。 header('Location:libwebtopay / redirec.php');也不会有帮助。你能帮助我吗?谢谢

1 个答案:

答案 0 :(得分:0)

您需要在提交按钮中添加value attribute。此外,您可以将其压缩为一种形式。顺便说一句,你也有无关的结束div标签。

<form action="" method="POST">
    <button type="submit" class="btn btn-success" aria-pressed="true" name="bank" value="1"><img src="img/cart.png"><b> Pay by bank</b></button> 
    <button type="submit" class="btn btn-success" aria-pressed="true" name="bank" value="2"><img src="img/cart.png"><b> Pay by bank</b></button>
    <button type="submit" class="btn btn-success" aria-pressed="true" name="bank" value="3"><img src="img/cart.png"><b> Pay by bank</b></button>
    <button type="submit" class="btn btn-success" aria-pressed="true" name="bank" value="4"><img src="img/cart.png"><b> Pay by bank</b></button>
</form>

您可能需要添加检查按下了哪个按钮(例如if ($_POST['bank'] == '3') { ... })。