开发者

PHP: Refresh my code

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">&#10004;</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.


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.


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


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.


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)


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);
?>


You may adding some parens around lastlogin + onlinetime:

if($row3['lastlogin'] + $onlinetime > time()){

change to

if(($row3['lastlogin'] + $onlinetime) > time()){


You could use a javascript reload:

<META HTTP-EQUIV="Refresh" CONTENT="360; /">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜