How can the header function be used for redirection in PHP scripts?

To perform a redirection in PHP scripts, the header function can be used to send a raw HTTP header to the browser. This function is typically used to redirect users to a different page or URL. By setting the "Location" header with the desired URL, the browser will automatically redirect the user to that location.

<?php
// Redirect to a different page
header('Location: https://www.example.com');
exit;
?>