How can PHP be used to redirect a page to another page after a certain amount of time?
To redirect a page to another page after a certain amount of time using PHP, you can use the `header()` function along with the `sleep()` function to delay the redirection. First, send the header with the `Location` parameter set to the destination URL, then use `sleep()` to pause the script execution for the desired amount of time before the redirection occurs.
<?php
// Redirect to the destination page after 5 seconds
header("Refresh: 5; URL=destination_page.php");
?>
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="5;url=destination_page.php">
</head>
<body>
<p>You will be redirected to the destination page in 5 seconds...</p>
</body>
</html>
Keywords
Related Questions
- How does using htmlentities for input data in a PHP application affect SQL injection prevention?
- What are best practices for securely handling user input in PHP to prevent SQL injection vulnerabilities, as discussed in the forum thread?
- How can PHP be used to automate the display of images from a specific folder on a website?