-
Notifications
You must be signed in to change notification settings - Fork 0
/
useronline.php
38 lines (35 loc) · 1.25 KB
/
useronline.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
include('system/db_connect.php');
if(!isset($_SESSION)){
session_start();
}
$id = $_SESSION['id'];
$session = session_id();
$time = time();
$time_check = $time-300;
$sql = "SELECT * FROM `online_users` WHERE user_id='$id'";
$result = mysqli_query($db, $sql) or die("Query fail : ".mysqli_error($db));
$count = mysqli_num_rows($result);
if($count == "0"){
$sql1 = "INSERT INTO `online_users`(user_id, session, `time`) VALUES ('$id', '$session', '$time')";
$result1 = mysqli_query($db, $sql1) or die("Query fail : ".mysqli_error($db));
}
else {
$sql2 = "UPDATE `online_users` SET `time`='$time' WHERE user_id = '$id'";
$result2 = mysqli_query($db, $sql2) or die("Query fail : ".mysqli_error($db));
}
$sql4 = "DELETE FROM `online_users` WHERE `time` < $time_check";
$result4 = mysqli_query($db, $sql4) or die("Query fail : ".mysqli_error($db));
class TestClass {
static function getOnline(){
global $db;
$obj = new stdClass();
$sql3 = "SELECT * FROM `online_users`";
$result3 = mysqli_query($db, $sql3) or die("Query fail : ".mysqli_error($db));
$count_user_online = mysqli_num_rows($result3);
$obj->online = $count_user_online;
$result3->close();
return json_encode($obj);
}
}
?>