How can a delay be implemented in a PHP script before redirecting using the header function?

To implement a delay before redirecting using the header function in PHP, you can use the sleep function to pause the script execution for a specified amount of time before sending the header for redirection. This can be useful for scenarios where you want to display a message or perform some action before redirecting the user to another page.

<?php
// Delay for 3 seconds
sleep(3);

// Redirect to the desired page
header("Location: newpage.php");
exit();
?>