Fou Fou - 2 months ago 17
PHP Question

PHP - auto refreshing page

I am using following code for a refreshing page, it is not reloading on completion. The following code is not working sometime.

$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");
echo "Watch the page reload itself in 10 second!";

Answer

Use a <meta> redirect instead of a header redirect, like so:

<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
    <head>
    <meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
    </head>
    <body>
    <?php
        echo "Watch the page reload itself in 10 second!";
    ?>
    </body>
</html>