[Solved] Find out how many users are online in PHP [closed]


Create a Table like this

CREATE TABLE `status` (
`session` char(100) NOT NULL default '',
`time` int(11) NOT NULL default '0'
);

Status.php

<title>User Online</title>
<?php
include ('config.php');
session_start();
$session=session_id();
$time=time();
$time_check=$time-600;
$tbl_name="status";
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE session='$session'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count=="0"){
$sql1="INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')";
$result1=mysql_query($sql1);
}
else {
"$sql2=UPDATE $tbl_name SET time="$time" WHERE session = '$session'";
$result2=mysql_query($sql2);
}
$sql3="SELECT * FROM $tbl_name";
$result3=mysql_query($sql3);
$count_user_online=mysql_num_rows($result3);
echo "User online : $count_user_online ";
$sql4="DELETE FROM $tbl_name WHERE time<$time_check";
$result4=mysql_query($sql4);
mysql_close();
?>

Follow my Tutorial for live code and screenshot : http://php.sysaxiom.com/user_online.php

1

solved Find out how many users are online in PHP [closed]