How can I redirect a php page to another php page?

Possible duplicate:
How to redirect users to another page?

I am a beginner in the field of programming .... I want to redirect a php page to another ... How is this possible in the simplest way? My concept is to simply go to the home page from the login page after checking the user ID and password.

+6
source share
7 answers
<?php header("Location: your url"); exit; ?> 
+12
source

While all the other answers work, they all have one big problem: the browser must decide what to do if they encounter the Location header. Typically, the browser stops processing the request and redirects to the URI specified in the Location header. But an attacker can simply ignore the Location header and continue to request it. In addition, there may be other things that cause the PHP interpreter to continue evaluating the script behind the Location heading, which is not how you planned.

Picture:

 <?php if (!logged_id()) { header("Location:login.php"); } delete_everything(); ?> 

What you want and expect is that users are not logged in, redirected to the login page, so that only registered users can delete everything. But if the script is executed after the Location header, everything is still deleted. So this is import, to ALWAYS put exit after the Location header, for example:

 <?php if (!logged_id()) { header("Location:login.php"); exit; // <- don't forget this! } delete_everything(); ?> 

So, to answer your question: redirect from a php page to another page (and not just php, you can redirect to any page this way), use this:

 <?php header("Location:http://www.example.com/some_page.php"); exit; // <- don't forget this! ?> 

A quick note: the HTTP standard says that you must specify absolute URLs in the Location header (http: // ... as in my example above), even if you just want to redirect another file in the same domain. But in practice, relative URLs (Location: some_page.php) work in all browsers, although they don’t comply with the standard.

+5
source
 <?php header('Location: /login.php'); ?> 

The above php script redirects the user to login.php on the same site

+1
source

Send the Location header for redirection. Keep in mind that this only works until you submit any other result.

 header('Location: index.php'); // redirect to index.php 
+1
source
 <?php header('Location: http://www.google.com'); //Send browser to http://www.google.com ?> 
+1
source

just you can put it and you will be redirected.

 <?php header("Location: your_page_name.php"); 

//your_page_name.php can be any page you want to redirect to

 ?> 
0
source

can use this to redirect

 echo '<meta http-equiv="refresh" content="1; URL=index.php" />'; 

content = 1 can be changed to another value to increase the delay before redirecting

-2
source

Source: https://habr.com/ru/post/910059/


All Articles