表单成功后php重定向

标签 php

使用 php 脚本允许人们将他们的电子邮件添加到邮件列表中。当它成功地将电子邮件写入 .txt 文档时,它会在白页上显示一条成功消息。我希望它重定向到我设计的页面,使其看起来像网站的其他部分。我在其他地方读到我需要使用 header 函数,但我不知道将其放在哪里,因为我的代码的前面部分包含输出。

我认为这是相关代码:

// Write to file if email doesn't already exist
    if ($emailexists != "yes") {

        // Write to the list and give success message
        fwrite($fh, "$_POST[email]\n");
        $msg = "Your e-mail address $EmailFix was successfully added to the list!";
    }

    // Close the list
    fclose($fh);
}

然后这个:

// Show success message if there was one and end script, and no errors were encountered
} elseif (isset($msg)) {
echo "<b>" . $msg . "</b>\n";
echo "</body>\n";
echo "</html>\n";
exit;
}

最佳答案

尝试使用

header("Location: http://...");

header("Location: filename.php");

在调用 header 函数之前确保没有 HTML 输出!

关于表单成功后php重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6232240/

相关文章:

PHP变量声明

php - 如何在 iOS 中使用 POST 请求向 SendGrid 发送照片电子邮件附件?

php - log4php : Cannot create log file

java - 亚马逊ec2查询制作

php - 如何打印group_concat函数的输出

sockets - 指定连接到 PHP CLI 套接字服务器的客户端的远程 IP 地址

php - mysql 按另一列计算不同的行并对结果进行分组

php - 文本字段中的符号与字段数据的显示有关

php - 删除链接不删除mysql数据库中的任何记录

php - 从正则表达式 PHP 中排除符号