如何将用户从 php 文件重定向回 Dreamhost 上的 `index.html`
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15411978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to redirect user from php file back to `index.html` on dreamhost
提问by dwstein
I'm setting up a simple landing page on DreamHost. It won't let me put php code in the file index.html. So, when user submits an email address, I use $_POSTto submit the email address to another page mail_auto.php.
我正在 DreamHost 上设置一个简单的登录页面。它不会让我将 php 代码放入文件中index.html。因此,当用户提交电子邮件地址时,我使用$_POST将电子邮件地址提交到另一个页面mail_auto.php。
After seeing a quick "email sent" message, I'd like the user to be directed back to the index.htmlpage from mail_auto.php.
在看到快速的“电子邮件已发送”消息后,我希望用户index.html从mail_auto.php.
header()looks a bit complex and seems to interfere with the execution of the balance of mail_auto.php.
header()看起来有点复杂,似乎干扰了mail_auto.php.
What's the best way to redirect the user?
重定向用户的最佳方式是什么?
回答by Raptor
To redirect user back to index.html, use the following:
要将用户重定向回 index.html,请使用以下命令:
header('Location: index.html');
exit;
Alternatively, if you want to display something like " Redirecting... " on screen, you can use the meta-refreshmethod , or JavaScript window.locationmethod with setTimeout
或者,如果您想在屏幕上显示诸如“重定向...”之类的内容,您可以使用该meta-refresh方法,或者使用window.location带有 的JavaScript方法setTimeout
The meta refresh method:
元刷新方法:
Add this to HTML <head>:
将此添加到 HTML <head>:
<meta http-equiv="refresh" content="2;url=index.html">
where 2 is number of seconds before the refresh is executed.
其中 2 是执行刷新前的秒数。
回答by ?lker Korkut
Just echo this javascript code end of the process.
只需在流程结束时回显此 javascript 代码即可。
<script>
window.location.href = 'http://www.yourwebsite.com';
</script>
回答by blamonet
Using the header is typically what I'd do.
使用标题通常是我会做的。
Have you thought about using JavaScript? It's not the best way, although it would work.
你有没有想过使用 JavaScript?这不是最好的方法,尽管它会奏效。
<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>

