Is there a way to make page display few seconds in php and redirect to another page ?
To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.
To set a permanent PHP redirect, you can use the status code 301. Because this code indicates an indefinite redirection, the browser automatically redirects the user using the old URL to the new page address.
Redirection from one page to another in PHP is commonly achieved using the following two ways: Using Header Function in PHP: The header() function is an inbuilt function in PHP which is used to send the raw HTTP (Hyper Text Transfer Protocol) header to the client.
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client). The 'header_value' in the function is used to store the header string.
The meta redirect is probably what you want, but you CAN do this in PHP too, like this:
<?php header("Refresh: 10;url=http://www.yourdestination.com/"); ?>
Where 10 is the number of seconds to wait.
EDIT Ok, I stand corrected. Corrected answer below.
You can either use PHP's header
function as shown elsewhere on this page.
If you want to do a refresh after the page is rendered, you can do so with JavaScript or a Meta Refresh. For users that block meta refreshs and have JavaScript disabled it is good practise to provide a link that can be clicked manually to get to the new target.
Example:
<?php header("Refresh: 2;url=http://www.example.com/"); ?>
<html>
<head>
<title>Redirects</title>
<meta http-equiv="refresh" content="2; URL=http://example.com" />
<script type="text/javascript">
window.setTimeout(function() {
location.href = 'http://example.com';
}, 2000);
</script>
</head>
<body>
<p>Click here if you are not redirected automatically in 2 seconds<br />
<a href="http://example.com">Example.com</a>.
</p>
</body>
</html>
Please also see the WCAG suggestions about Automatic Page Refreshes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With