What are some best practices for implementing a page redirect after a specific time in PHP?
When implementing a page redirect after a specific time in PHP, it is important to use the `header()` function to send a raw HTTP header to perform the redirection. To delay the redirect, you can use the `sleep()` function to pause the script execution for a specified number of seconds before redirecting.
<?php
// Delay the redirect for 5 seconds
sleep(5);
// Redirect to the desired page
header("Location: http://example.com/newpage.php");
exit;
?>
Keywords
Related Questions
- What is the difference between accessing a URL with "www." and without it, and why is it important in PHP?
- What is the recommended approach for handling line breaks in PHP text fields?
- How can the proper use of PHP object-oriented style and procedural style prevent errors and improve code readability in database operations?