如何从PHP脚本转到新的Html页面?

时间:2022-04-23 20:01:35

After the php script is over, how do I go to another html page?

php脚本结束后,如何转到另一个html页面?

3 个解决方案

#1


17  

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:

如果是,你有两个解决方案:

  1. Do not output anything, and after your script stopped executing, use the header() PHP function:

    不要输出任何东西,在您的脚本停止执行后,使用header() PHP函数:

    header('Location: http://example.com/some/url');
    

    where you should replace the example URL with your own.

    您应该将示例URL替换为您自己的URL。

  2. If you are outputting the HTML page and sending it gradually to the user, you can just put JavaScript redirection script at the end of the page (so after everything has been sent):

    如果你正在输出HTML页面并逐渐发送给用户,你可以在页面的末尾加上JavaScript重定向脚本(所以在发送完所有内容后):

    <script>
    window.location = 'http://example.com/some/url';
    </script>
    

Does any of these solutions work for you?

这些解决方案对你有用吗?

#2


4  

header('Location: /page.html');

#3


2  

Make sure you don't output anything else, then simply

确保不输出任何其他内容,然后简单地输出

header('Location: http://www.example.com/');

#1


17  

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:

如果是,你有两个解决方案:

  1. Do not output anything, and after your script stopped executing, use the header() PHP function:

    不要输出任何东西,在您的脚本停止执行后,使用header() PHP函数:

    header('Location: http://example.com/some/url');
    

    where you should replace the example URL with your own.

    您应该将示例URL替换为您自己的URL。

  2. If you are outputting the HTML page and sending it gradually to the user, you can just put JavaScript redirection script at the end of the page (so after everything has been sent):

    如果你正在输出HTML页面并逐渐发送给用户,你可以在页面的末尾加上JavaScript重定向脚本(所以在发送完所有内容后):

    <script>
    window.location = 'http://example.com/some/url';
    </script>
    

Does any of these solutions work for you?

这些解决方案对你有用吗?

#2


4  

header('Location: /page.html');

#3


2  

Make sure you don't output anything else, then simply

确保不输出任何其他内容,然后简单地输出

header('Location: http://www.example.com/');