Search code examples
phprefresh

how to refresh page in a specific time


i tried this code in my wp page but its not work

<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
date("d-m-Y H:i:s");
$time= date("H:i:s");
if($time == "03:40:00")
{
    echo "The new page loading in 10 seconds!";
	header("Refresh: $sec; url=$page");
}
?>


Solution

  • this code better i think, thank you Andrew Moore !

    <script>
    function refreshAt(hours, minutes, seconds) {
        var now = new Date();
        var then = new Date();
    
        if(now.getHours() > hours ||
           (now.getHours() == hours && now.getMinutes() > minutes) ||
            now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
            then.setDate(now.getDate() + 1);
        }
        then.setHours(hours);
        then.setMinutes(minutes);
        then.setSeconds(seconds);
    
        var timeout = (then.getTime() - now.getTime());
        setTimeout(function() { window.location.reload(true); }, timeout);
    }
    refreshAt(16,30,0); //Will refresh the page at 4:30pm
    </script>