What are the best practices for displaying success messages and delaying redirection in PHP forms?

When displaying success messages in PHP forms, it is important to delay the redirection to ensure that the user has enough time to read the message before being redirected. One way to achieve this is by using the PHP header() function along with a short delay using the sleep() function.

<?php
if ($form_submitted_successfully) {
    echo "Form submitted successfully. Redirecting in 3 seconds...";
    sleep(3);
    header("Location: success_page.php");
    exit();
}
?>