简体   繁体   中英

how i use of header tag to redirect page in php

I want to redirect the page on the if condition.

this is my html page

<form name="frmpayment" enctype="application/x-www-form-urlencoded" action="payment_mode.php" method="POST">
    <table>
    <tr>
    <td><label for="mode">Select Mode</label></td>
    <td>
   <select name="selectmode" id="slctmode" size="1">
   <option selected>Selected Mode</option>
   <option value="1">Online Payment</option>
   <option value="2">Cash on Delevery</option>
    </select></td></tr>
    <tr><td></td><td>
    <input type="submit" name="btnmode" value="Done"/> 
         </td></tr></table>

    </form>

and this is my payment_mode.php page

<?php
$i= $_POST['selectmode'];

if($i>1)
    {
        header("Location : detail.php");

    }
else
    {
        header("Location : home.php");

    }

?>

bt it does not redirect the page detail.php and home.php

Try:

<?php
$i= $_POST['selectmode'];

if($i>1)
    {
        header("Location: detail.php");
        exit;

    }
else
    {
        header("Location : home.php");
        exit;

    }

Also, make sure on this page there is nothing being outputted before your calling the header() function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM