【问题标题】:Redirect after form submit PHP [duplicate]表单提交PHP后重定向[重复]
【发布时间】:2014-11-09 15:32:36
【问题描述】:

我在提交表单后尝试重定向用户。我目前使用 Header("Location:http://www.google.com") 作为测试,但提交后它仍然在我的网站上。

我做错了什么?

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: Website'; 
    $to = 'contact@joakimsorensen.se'; 
    $subject = 'Hello';
    $human = $_POST['human'];


    $body = "From: $name\n E-Mail: $email\n Message:\n $message";



     if ($_POST['submit'] && $human == '4') {

    if (mail ($to, $subject, $body, $from)) {

    header("Location: http://www.google.com");
    echo 'great';
    } else { 
        echo '<span style="color:red"><p>Something went wrong, go back and try again!</p></span>'; 
    }
     } else if ($_POST['submit'] && $human != '4') {
    echo '<span style="color:red"><p>You answered the anti-spam question incorrectly!</p></span>';
    }
?>

它只是从回声中打印出“很棒”。

【问题讨论】:

标签: php html forms redirect


【解决方案1】:

我认为问题在于标头已经发送。尝试使用

?>
<script type="text/javascript">
   window.location="http://www.google.com";
</script>
<?php

而不是

 header("Location: http://www.google.com");

【讨论】:

    猜你喜欢
    • 2016-09-22
    • 2013-09-10
    • 2016-10-05
    • 2014-11-27
    • 2013-04-13
    • 1970-01-01
    相关资源
    最近更新 更多