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
- What steps can be taken to troubleshoot and resolve session ID inconsistencies when transitioning from PHP 5 to PHP 7?
- Are there any specific resources available in German for learning about PHP as a stand-alone language?
- What issue arises when PHP ignores decimal places in multiplication calculations?