Skip to content
PHP Logo

How can a PHP script use the header() function to redirect back to a specific page, like login.php?

To redirect a PHP script back to a specific page like login.php, you can use the header() function with the Location parameter set to the desired page's URL. This will send a raw HTTP header to the browser, instructing it to redirect to the specified page. Make sure to call this function before any output is sent to the browser to avoid any errors.

php
<?php
// Redirect to login.php
header("Location: login.php");
exit;
?>