【发布时间】: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>';
}
?>
它只是从回声中打印出“很棒”。
【问题讨论】:
-
尝试使用单引号
''而不是""。 -
而不是
echo 'great';试试 die();参考:[stackoverflow.com/questions/768431/… [1]:stackoverflow.com/questions/768431/…