What is the correct way to handle redirection after a certain delay in PHP?
When you want to redirect a user to a different page after a certain delay in PHP, you can achieve this by using the `header()` function along with the `sleep()` function. First, send the headers to indicate a redirect, then use `sleep()` to delay the redirection. After the delay, use `header()` again to specify the new location for the redirection.
<?php
// Redirect after a 5-second delay
header("Refresh: 5; url=destination.php");
echo "You will be redirected to the destination page in 5 seconds...";
sleep(5);
header("Location: destination.php");
exit;
?>
Related Questions
- What potential security risks or vulnerabilities could arise from using the "file_get_contents" function to retrieve data from external sources in PHP scripts, especially when dealing with SSL encrypted pages?
- What is the purpose of the fclose function in PHP when writing to a text file, and when should it be used?
- What are the advantages and disadvantages of using a pre-built open source ticket system for PHP?