Refresh a page using PHP

04/07/2020 02:30:02

How can I refresh a page using PHP periodically? If I can not do it by PHP, what is the best recommended scenario?

Verified Answer (256 Votes)

01/02/2014 12:48:17

You can do it with PHP:


It refreshes your current page, and if you need to redirect it to another page, use following:

header("Refresh:0; url=page2.php");

Answer #2 (108 Votes)

09/12/2012 12:44:59

In PHP you can use:

$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");

Or just use JavaScript's window.location.reload().


Answer #3 (17 Votes)

07/31/2013 19:49:25

You sure can refresh a page periodically using PHP:

    header("refresh: 3;");

This will refresh the page every three seconds.

Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.