表单成功后php重定向
使用 php 脚本允许人们将他们的电子邮件添加到邮件列表。当它成功地将电子邮件写入 .txt 文档时,它会在白页上显示一条成功消息。我希望它重定向到我设计的页面,使其看起来像网站的其他部分。我在其他地方读到我需要使用标头函数,但我不知道将其放在哪里,因为我的代码的前面部分包含输出。
我认为这是相关的代码:
// 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;
}
Using php script to allow people to add their email to a mailing list. When it successfully writes the email to the .txt doc it displays a success message on a white page. I want it to redirect to a page I've designed to look like the rest of the site. I've read elsewhere that I need to use the header function, but I can't figure out where to put it since the preceding portion of my code contains outputs.
I think this is the relevant code:
// 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);
}
Then this:
// 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
或
在调用标头函数之前确保没有 HTML 输出!
Try using
or
Make sure there's no HTML output before calling the header function!
您是否希望此消息仍然显示,然后将其重定向到其他地方?或者您是否想一起丢弃此消息并将他们定向到具有类似消息的不同页面?
您可以按原样显示该页面,并包含另一个回显以触发重定向:
Do you want this message to still show and THEN redirect them somewhere else? Or do you want to discard this message all together and direct them to a different page that will have a similar message?
You could show that page as is, and include another echo to trigger a redirect:
如果您之前的代码包含无法使用 javascript 重定向的代码:
您应该通知用户他/她将被重定向。
If your previous code contains code than you can use javascript redirection:
You should norify the user the user that s/he will be redirected.