Do you want to redirect your page to another page in PHP? Then I will show you how you can make redirection from current page to another page in php.
To redirect to another page in php, you can use the header() function to send the raw HTTP header and redirect to your page. Let’s have a look at in details with example.
The header() function is built-in function and it used to send a raw HTTP header but make sure header() call before sent the actual output.
header(string $header, bool $replace = true, int $response_code = 0)
$header: used to hold the header string and it can be two types of string, first one is start the string with “HTTP/” and second is “Location:”.
$replcae: used to indicates whether the header should replace a previous similar header, or add a second header of the same type. It is boolean and optional parameter.
$response_code: Sets the HTTP response code to the given value. This option only has an impact if the header isn’t blank.
Note: Remember that header() must be called before sending any output, either by normal HTML tags, blank lines in a file, or from PHP. OR use the die() or exit() function after the header() function.
Being Tricky 😉