2013-05-08 99 views
2

我想在if條件中重定向頁面。我如何使用標題標記在php中重定向頁面

這是我的html頁面

<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> 

,這是我payment_mode.php頁

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

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

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

    } 

?> 

BT不重定向頁面detail.php和home.php

+0

嘗試完整URL。 – karmafunk 2013-05-08 09:11:23

+1

可能是因爲你早些時候迴應了一些事情。看看這篇文章: http://stackoverflow.com/questions/2710079/php-header-location-redirect-doesnt-work-why – imclickingmaniac 2013-05-08 09:13:53

+0

你有任何錯誤信息? – ajtrichards 2013-05-08 09:14:58

回答

1

嘗試:

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

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

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

    } 

另外,請確保在此頁面上,在您撥打header()功能之前沒有輸出任何內容。