满足条件时重定向到特定页面

时间:2015-03-23 04:51:29

标签: forms redirect

我正在处理的表单会在用户输入

的文本框中输入邮政编码后重定向用户
11111 and 22222 they will redirected to google.com
33333 and 44444 they will redirected to yahoo.com
55555 and 66666 they will redirected to bing.com

这是我的redirect_form.php

<form method="post" id="#form" action="redirect_form.php" >
        <input type='text' name="zip" id="zip" placeholder='Enter Your Zip Code'/>      
        <input type='submit' id='btn' name="submit" Value='Submit' /><br />             
    <?php
        include "include/redirect.php";
    ?>  
    </form>

这里是我的redirect.php

<?php
if(isset($_POST['submit'])){
        //Fetching variables of the form which travels in URL
        $zip = $_POST['zip'];
            if($zip =='11111' || $zip =='22222')
        {           
          //To redirect form on a particular page
            header("Location:http://www.google.com");
        }
            else if($zip =='33333' || $zip =='44444')
        {           
          //To redirect form on a particular page
            header("Location:http://www.yahoo.com");
        }
        else if($zip =='55555' || $zip =='66666')
        {           
          //To redirect form on a particular page
            header("Location:http://bing.com");
        }
        else{
            ?><span><?php echo "Please enter your Zip code.....!!!!!!!!!!!!";?></span> <?php
         }      
    }
?>

但是在我测试了我的表单之后,例如我输入了11111,它给了我这个错误:

Warning: Cannot modify header information - headers already sent by (output started at /home2/mighty1/public_html/epic/redirect_form/redirect_form.php:12) in /home2/mighty1/public_html/epic/redirect_form/include/redirect.php on line 8

redirect.php中的第8行是header("Location:http://www.yahoo.com");

有人可以帮助我:)。

谢谢

1 个答案:

答案 0 :(得分:1)

您的重定向表单正在返回内容,这需要发送标头。您需要将表单操作更改为include / redirect.php并将其从包含中删除。