Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php script to stay for few second in some page and redirect

Tags:

php

Is there a way to make page display few seconds in php and redirect to another page ?

like image 214
ktm Avatar asked Sep 22 '10 11:09

ktm


People also ask

How do I automatically redirect a page after 5 seconds?

To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window. location. href object.

How do I automatically redirect in PHP?

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.

How redirect data from one page to another in PHP?

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.

How a page is redirected in PHP?

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.


2 Answers

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.

like image 159
mkoistinen Avatar answered Nov 15 '22 07:11

mkoistinen


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.

like image 39
Gordon Avatar answered Nov 15 '22 06:11

Gordon