How to redirect a page in PHP?
Use the header() function with the Location header to redirect to another page. Always call exit after it, so the rest of the script does not run.
<?php
header("Location: https://tutorialsclass.com/");
exit;
?>
For a permanent redirect, pass the status code as the third parameter.
<?php
header("Location: https://tutorialsclass.com/new-page/", true, 301);
exit;
?>
Note:
The header() function must be called before any output (even a space or blank line). Otherwise PHP shows a “headers already sent” warning. See PHP header() function.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Forms Handling |
| PHP Send Mail |
| PHP header() Function |
| PHP mail() Function |
| Exercises & Assignments |
|---|
| Create a PHP Form with 2 fields Name and Hobbies |