How can the PHP header function be properly used in the context of redirecting users?

When redirecting users in PHP, the header function can be used to send a raw HTTP header to the browser, which includes the "Location" header to redirect the user to a new page. It's important to call the header function before any output is sent to the browser to avoid any errors. Additionally, using the "exit" function after setting the header will ensure that no further code is executed.

<?php
// Redirect user to a new page
header("Location: newpage.php");
exit;
?>