Question

Ok I have a page called inbox.php which is an inbox in receiving messages from other users. The new messages will load though every time the user "refreshes" the page. How can I write this in PHP where the inbox.php will automatically refreshes itself every 5 seconds? Thanks and peace.

Was it helpful?

Solution 2

It can be done with one simple meta tag

<meta http-equiv="refresh" content="5; ,URL=http://www.example.com/index.php">
                                    ^== seconds         ^=== URL

OTHER TIPS

You can redirect the page every interval by placing this code before html code..

 $urlRefresh = "thispage.php";
 header("Refresh: 5; URL=\"" . $urlRefresh . "\""); // redirect in 5 seconds

But this is better I think to do with javascript insteed..

link for tutorial

You should use client side scripting to do this. Easiest is in javascript. For example in your body tag:

<body onload="setTimeout(window.location.reload,5000);">

But you might want to reconsider refreshing the entire page each time. Consider loading just the changes with Ajax.

There could be more than one approach to this task:

  1. The better and more efficient being AJAX, so that only the data part gets updated, and rest of the page stays same. check the below link for more details AJAX reload every 10 seconds

  2. META tag in your HTML page

  3. Javascript:

    reloadTimer(function(){ window.location.reload(1); }, 5000);//using micro seconds

Check the below link

How to reload page every 5 second?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top