Can you include a time delay in a header redirect in PHP?
To include a time delay in a header redirect in PHP, you can use the `header()` function in combination with the `sleep()` function. The `header()` function is used to send a raw HTTP header, including the redirect location, and the `sleep()` function is used to pause the script execution for a specified number of seconds before the redirect occurs.
<?php
// Set the delay time in seconds
$delay = 5;
// Wait for the specified delay time
sleep($delay);
// Redirect to the desired location after the delay
header("Location: https://www.example.com");
exit;
?>
Keywords
Related Questions
- What are the best practices for deleting directories with files using PHP FTP functions?
- In what scenarios would it be recommended to seek support from Adobe or other software providers when encountering issues with sending PDF attachments via email using PHP?
- What are the potential pitfalls of using fopen() to create files in PHP?