Reputation: 10121
Hello i want to refresh my php every 3 sec this is what i have:
<?php
session_start();
include "../config.php";
$time = time();
$sql1 = "UPDATE login SET lastlogin = '" .$time. "' WHERE id = '" .$_SESSION['userid']. "'";
$res1 = mysql_query($sql1) or die(mysql_error());
$onlinetime = "10"; // 10 seconds
$sql3 = "SELECT * FROM login ORDER BY lastlogin DESC";
$res3 = mysql_query($sql3);
while($row3 = mysql_fetch_array($res3)){
if($row3['lastlogin'] + $onlinetime > time()){
echo '<b><font color="green">✔</font></b> <u>'.$row3['name'].'</u><br />';
}else{
echo "<b><font color='red'>X</font></b> <u>".$row3['name']."</u><br />";
}
}
?>
This is not refreshing which is really irritating. It shows who's online at my chatbox. Someone help? Thanks.
Upvotes: 0
Views: 1152
Reputation: 5097
You could refresh using PHP header or something by that means. It works for me every time.
<?php
$url = 'http://google.com/'; $timeout = 5; //Directed URL and timeout.
header('Refresh: ' . $timeout . ';url=' . $url);
?>
Upvotes: 1
Reputation: 20475
You could use a javascript reload:
<META HTTP-EQUIV="Refresh" CONTENT="360; /">
Upvotes: 0
Reputation: 12993
I have no idea what you're trying to do. The code has no mention of a refresh in it.
You could put the following in the element of your HTML to force the client to refresh every three seconds.
<meta http-equiv="refresh" content="3" />
Ian
Upvotes: 3
Reputation: 1507
You may adding some parens around lastlogin + onlinetime
:
if($row3['lastlogin'] + $onlinetime > time()){
change to
if(($row3['lastlogin'] + $onlinetime) > time()){
Upvotes: 0
Reputation: 25147
I'd suggest using the <meta http-equiv="refresh" content="5" />
tag in the <head>
section. This does not depend on JavaScript, and every major browser has this feature implemented.
Upvotes: 7
Reputation: 3323
Refreshing a browsers content is something the browser should do. Either use the Redirect-After
HTML meta-tag (which will result in "flickering"), or use some Javascript to reload the site's content (see AJAX)
Upvotes: 1
Reputation: 58992
The best solution is to use ajax and poll a php script which checks for online users every X seconds.
I highly recommend jQuery for the ajax-part.
Upvotes: 1