How can you delay a page redirect using PHP's header function?

When using PHP's header function to redirect a page, you can delay the redirect by using the sleep function before sending the header. This can be useful in situations where you want to display a message to the user before redirecting them to another page.

<?php
// Delay the redirect by 3 seconds
sleep(3);
header("Location: newpage.php");
exit;
?>