Refresh a page using PHP

How can I periodically refresh a page using PHP? If I cannot do this with PHP, what is the best recommended scenario?

+122
php refresh
Sep 12
source share
13 answers

You can do this with PHP:

header("Refresh:0"); 

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

 header("Refresh:0; url=page2.php"); 
+223
Jan 02 '14 at 7:48
source share

In PHP you can use:

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

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

+102
Sep 12
source share

You can periodically refresh the page using PHP:

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

This will refresh the page every three seconds.

+15
Jul 31 '13 at 14:49
source share

This is just possible with header () in PHP:

 header('Refresh: 1; url=index.php'); 
+14
Jul 31 '14 at 9:44
source share

In addition to all the PHP methods for updating the page, the page will also be updated with the following HTML meta tag:

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

See Meta refresh - "automatically refresh the current web page or frame at a specified time interval"

You can set the time within the content value.

+11
Sep 12 '12 at 7:45
source share

I found two ways to update PHP content:

1. Using meta HTML:

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

2. Using the 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;"); 
+11
Nov 04 '14 at 16:24
source share

You cannot do this in PHP . After the page loads, PHP dies and gets out of control.

You have several options:

  • Use javascript
  • Use the update meta tag, <meta http-equiv="refresh" content="5">

I think updating the meta tag is the easiest and most convenient.

+2
Sep 12
source share

Display meta like this:

The URL is where the page should be redirected after the update.

 echo "<meta http-equiv=\"refresh\" content=\"0;URL=upload.php\">"; 
+2
Sep 22 '14 at 4:50
source share

Adding this meta tag to PHP can help:

 echo '<META HTTP-EQUIV="Refresh" Content="0; URL=' . $location . '">'; 
+2
Mar 09 '17 at 11:28
source share

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

+2
Apr 21 '17 at 9:02 on
source share

PHP is a server-side language, so you cannot refresh a page using PHP, but JavaScript is the best option for refreshing a page:

 location.reload(); 

Location Location reload () method.

+1
Sep 12
source share

You can update using JavaScript. Instead of refreshing the page completely, you can refresh the content in a div. Then, with JavaScript, you can only refresh this single div, and it works faster than a full page refresh.

+1
Sep 12 '12 at 8:13
source share

One trick is to add a random number to the end of the URL. Thus, you do not need to rename the file every time. For example:

 echo "<img src='temp.jpg?r=3892384947438'>" 

The browser will not cache it until a random number is different, but the web server will ignore it.

0
Sep 19 '17 at 21:39 on
source share



All Articles