使用 javascript 的 PHP 页面重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15964560/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:16:55  来源:igfitidea点击:

PHP Page redirection with javascript

phpredirect

提问by anshu

a small problem ! I have a login form in a PHP file. I have used javascript validation for the form. On a login success scenario i am redirecting the user to their home page.

一个小问题!我在 PHP 文件中有一个登录表单。我已经对表单使用了 javascript 验证。在登录成功的情况下,我将用户重定向到他们的主页。

I have used header("Location:index.php").

我用过header("Location:index.php")

I know that the header must be before any output must be sent to the browser. My question is there any walk around to do this redirection?

我知道标题必须在任何输出必须发送到浏览器之前。我的问题是有任何走动来做这个重定向吗?

回答by Tom

You could use

你可以用

<script>
    window.location = 'http://www.example.com/newlocation';
</script>

to redirect after the headers are sent.

在发送标头后重定向。

回答by chandresh_cool

If you using javascript Use this

如果您使用 javascript 使用这个

window.location.href = "index.php";

回答by Thirumalai murugan

If you are ready to use the JavaScript you can use any one of the following method.

如果您准备使用 JavaScript,您可以使用以下任何一种方法。

1.window.location.assign('http://www.example.com');
2.window.location = 'http://www.example.com';
3.window.location.href = 'http://www.example.com';

回答by Raptor

Apart from using header()to redirect, you can use meta refresh method, or JS window.locationmethod.

除了header()用于重定向之外,您还可以使用元刷新方法,或 JSwindow.location方法。