Simplest way to redirection from one page to another in PHP:
Using Header Function
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.
Syntax:
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:
<?php
// Redirect browser
exit
;
?>
The header() function is commonly used for redirection purposes.
```
```
In the code snippet above, we use the header() function with the “Location” parameter to specify the URL of the page we want to redirect to. You can replace “https://example.com/new-page.php” with the actual URL of the destination page.
After sending the header, it is important to include the exit; statement to stop the execution of any remaining PHP code. This ensures that the redirection happens immediately and prevents any further processing.
Using header function we can redirect in PHP