Advertisement
Advertisement


Refresh a page using PHP


Question

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

2017/07/16
1
151
7/16/2017 4:36:00 AM

Accepted Answer

You can do it with PHP:

header("Refresh:0");

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

header("Refresh:0; url=page2.php");
2014/04/10
281
4/10/2014 7:36:00 PM


You sure can refresh a page periodically using PHP:

<?php
    header("refresh: 3;");
?>

This will refresh the page every three seconds.

2014/04/10

That is simply possible with header() in PHP:

header('Refresh: 1; url=index.php');
2019/07/19

I've found two ways to refresh PHP content:

1. Using the HTML meta tag:

echo("<meta http-equiv='refresh' content='1'>"); //Refresh by HTTP 'meta'

2. Using PHP refresh rate:

$delay = 0; // Where 0 is an example of a time delay. You can use 5 for 5 seconds, for example!
header("Refresh: $delay;"); 
2019/07/19

Besides all the PHP ways to refresh a page, the page will also be refreshed with the following HTML meta tag:

<meta http-equiv="refresh" content="5">

See Meta refresh - "automatically refresh the current web page or frame after a given time interval"

You can set the time within the content value.

2019/07/20

header('Location: .'); seems to refresh the page in Chrome, Firefox, Edge, and Internet Explorer 11.

2019/07/19