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.
4 Answers
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..

- 11,552
- 11
- 40
- 55
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.

- 11,762
- 7
- 33
- 61
It can be done with one simple meta tag
<meta http-equiv="refresh" content="5; ,URL=http://www.example.com/index.php">
^== seconds ^=== URL

- 8,780
- 3
- 42
- 47
There could be more than one approach to this task:
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
META tag in your HTML page
Javascript:
reloadTimer(function(){ window.location.reload(1); }, 5000);//using micro seconds
Check the below link

- 1
- 1

- 475
- 1
- 11
- 33