Redirection from one page to another in PHP is commonly achieved using the following two ways:
Using Header Function in PHP:
The header() function is an inbuilt function in PHP which is used to send the raw HTTP (Hyper Text Transfer Protocol) header to the client.
header( $header, $replace, $http_response_code )
Parameters: This function accepts three parameters as mentioned above and described below:
- $header: This parameter is used to hold the header string.
- $replace: This parameter is used to hold the replace parameter which indicates the header should replace a previous similar header, or add a second header of the same type. It is optional parameter.
- $http_response_code: This parameter hold the HTTP response code.
Below program illustrates the header() function in PHP:
Note: The die() or exit() function after header is mandatory. If die() or exit() is not put after after the header(‘Location: ….’) then script may continue resulting in unexpected behavior. For example, result in content being disclosed that actually wanted to prevent with the redirect (HTTP 301).
URL: https://ide.geeksforgeeks.org/tryit.php Hostname: ide.geeksforgeeks.org Protocal: https:
- How to use Meta Tag to redirect an HTML page?
- How to redirect a page to another page in HTML ?
- ES6 | Page Redirect
- How to redirect a user to the registration if he has not logged in?
- How to redirect to a particular section of a page using HTML or jQuery?
- How to force redirect to a particular route in angular?
- How to make dynamic chart in PHP using canvasJS?
- How to make PDF file downloadable in HTML link using PHP ?
- How to make a spider-bot in PHP ?
- How to make asynchronous HTTP requests in PHP ?
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- Which language should you learn first if you want to make an app?
- C/C++ program to make a simple calculator
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.