如何在php中重定向另一个页面? [重复]

问题描述:

This question already has an answer here:

I want to start another page when a user filled out my login form and see another page. I have an index.php and login.php for action file. Now can u tell me how can i redirect to another page via php codes?

</div>

此问题已经存在 这里有一个答案: p>

  • 如何在PHP中进行重定向? 31 answers span> li> ul> div>

    我想在用户填写登录表单时启动另一页 看到另一页。 我有一个index.php和login.php的动作文件。 现在可以告诉我如何通过php代码重定向到另一个页面? p> div>

This will work if you haven't written anything on the page yet:

header( 'Location: http://www.yoursite.com/new_page.html' ) ;

If you have, you'll have to use javascript for redirection:

<script>window.location.href = "http://www.yoursite.com/new_page.html";</script>

use this

header( 'Location: http://www.yoursite.com/new_page.html' ) ;

or

header( 'Location: /somepage.php' ) ;

for a local page.

Before printing any HTML on the page, use the header function to tell the location for the request made by the user it's somewhere else, causing a redirect to that page.

header('Location: login.php');

to redirect to another page use function header