我正在 DreamHost 上设置一个简单的登录页面。它不会让我将 php 代码放入文件 index.html
中。因此,当用户提交电子邮件地址时,我使用 $_POST
将电子邮件地址提交到另一个页面 mail_auto.php
。
在快速看到“电子邮件已发送”消息后,我希望将用户从 mail_auto.php
引导回 index.html
页面。
header()
看起来有点复杂,似乎干扰了 mail_auto.php
平衡的执行。
重定向用户的最佳方式是什么?
最佳答案
要将用户重定向回 index.html,请使用以下命令:
header('Location: index.html');
exit;
或者,如果您想在屏幕上显示类似“正在重定向...”的内容,您可以使用 meta-refresh
方法,或 JavaScript window.location
使用 setTimeout
的方法
元刷新方法:
将此添加到 HTML <head>
:
<meta http-equiv="refresh" content="2;url=index.html">
其中 2 是执行刷新前的秒数。
关于php - 如何将用户从 php 文件重定向回 dreamhost 上的 `index.html`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15411978/