如何从 PHP 脚本转到新的 Html 页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9541238/
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 go to new Html page from PHP script?
提问by user1244153
After the php script is over, how do I go to another html page?
php脚本结束后,如何跳转到另一个html页面?
回答by Tadeck
Why would you want to do that? When the page is over(which I understand as the script ended execution), it is usually sent to the client and then it can be viewed by the user. So, basically, what you are trying to do is to redirect the user after the script stopped executing.
你为什么想这么做?当页面结束时(我理解为脚本结束执行),它通常被发送到客户端,然后它可以被用户查看。因此,基本上,您要做的是在脚本停止执行后重定向用户。
If so, you have two solutions available:
如果是这样,您有两种可用的解决方案:
Do not output anything, and after your script stopped executing, use the
header()
PHP function:header('Location: http://example.com/some/url');
where you should replace the example URL with your own.
If you are outputting the HTML page and sending it gradually to the user, you can just put JavaScript redirection scriptat the end of the page (so after everything has been sent):
<script> window.location = 'http://example.com/some/url'; </script>
不要输出任何东西,在你的脚本停止执行后,使用
header()
PHP 函数:header('Location: http://example.com/some/url');
您应该用您自己的 URL 替换示例 URL。
如果您正在输出 HTML 页面并逐渐将其发送给用户,您可以将 JavaScript 重定向脚本放在页面的末尾(因此在所有内容都已发送之后):
<script> window.location = 'http://example.com/some/url'; </script>
Does any of these solutions work for you?
这些解决方案中的任何一个对您有用吗?
回答by ceejayoz
header('Location: /page.html');
回答by trapper
Make sure you don't output anything else, then simply
确保您不输出任何其他内容,然后只需
header('Location: http://www.example.com/');