i need to know the users on line or off line, that is my code:
[PHP]
$time = time();
$timech = time()-7;
$user = $_SERVER['REMOTE_ADDR'];
$session = $_SESSION['chat'];
$host = "localhost" ;
$username = "root";
$password = "";
$dbname = "chat";
$connect = mysql_connect(" $host", "$username" , "$password" );
mysql_select_db ("$dbname");
$online = mysql_query("SE LECT * FROM online");
while($row = mysql_fetch_arr ay($online)){
if($row['session']==$session){
$uexi = true;
}
}
if($uexi == true){mysql_que ry("UPDATE online SET time='$time',us er='$user' WHERE session = '$ses'");}else{ mysql_query("IN SERT INTO online (session, time, user) VALUES ('$ses', '$time' ,'$user')");}
mysql_query("DE LETE FROM online WHERE time<$timech");
[/PHP]
i used this code in my little chat room but i want to use another technique because i think that code will effect in the site simplicity, in my chat room I'm using Ajax to check every second if the user on line or not, i mean that this code every one will enter the site will check if any one if his session time expired or not this code will take long time to users having slow connection.
[PHP]
$time = time();
$timech = time()-7;
$user = $_SERVER['REMOTE_ADDR'];
$session = $_SESSION['chat'];
$host = "localhost" ;
$username = "root";
$password = "";
$dbname = "chat";
$connect = mysql_connect(" $host", "$username" , "$password" );
mysql_select_db ("$dbname");
$online = mysql_query("SE LECT * FROM online");
while($row = mysql_fetch_arr ay($online)){
if($row['session']==$session){
$uexi = true;
}
}
if($uexi == true){mysql_que ry("UPDATE online SET time='$time',us er='$user' WHERE session = '$ses'");}else{ mysql_query("IN SERT INTO online (session, time, user) VALUES ('$ses', '$time' ,'$user')");}
mysql_query("DE LETE FROM online WHERE time<$timech");
[/PHP]
i used this code in my little chat room but i want to use another technique because i think that code will effect in the site simplicity, in my chat room I'm using Ajax to check every second if the user on line or not, i mean that this code every one will enter the site will check if any one if his session time expired or not this code will take long time to users having slow connection.
Comment