users-online
Code (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
39
40
41
42
43
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
39
40
41
42
43
<?php
/* Configuratie van MySQL */
$mysql_host = "localhost";
$mysql_user = "username";
$mysql_pwd = "passwd";
$mysql_db = "database_name";
$mysql_port = 3306; // dit is de standaard MySQL port
$max_time = 600; // de timeout... Hoe lang is iemand non-actief totdat
// hij/zij uit de database wordt verwijderd? (in sec.)
/* Vanaf hier gaat de rest automatisch */
$db = @mysql_connect($mysql_host . ":" . $mysql_port,$mysql_user,$mysql_pwd)
or die ("Could not connect to MySQL server!");
mysql_select_db($mysql_db,$db)
or die ("Could not select database " . $mysql_db);
$tables_result = mysql_list_tables($mysql_db);
$TABLE_EXISTS = FALSE;
for ($c = 0; $c < mysql_num_rows($tables_result); $c++)
if (mysql_tablename($tables_result,$c) == "users_online") { $TABLE_EXISTS = TRUE; }
if (!$TABLE_EXISTS)
mysql_query("CREATE TABLE users_online (id INT NOT NULL auto_increment PRIMARY KEY, sess_id VARCHAR(100), time DATETIME)",$db);
session_start();
$id = session_id();
$query = mysql_query("SELECT * FROM users_online WHERE sess_id = '$id'",$db);
if (mysql_affected_rows() > 0)
mysql_query("UPDATE users_online SET time = now() WHERE sess_id = '$id'",$db);
else
mysql_query("INSERT INTO users_online VALUES(0,'$id',now())",$db);
$now = date("U") - $max_time; // $now = UNIX timestamp - $max_time
$now = date("Y-m-d H:i:s",$now);
mysql_query("DELETE FROM users_online WHERE time < '$now'",$db);
$count_query = mysql_query("SELECT COUNT(*) as TOTAL FROM users_online",$db);
$user_count = mysql_result($count_query,0,"TOTAL");
?>
/* Configuratie van MySQL */
$mysql_host = "localhost";
$mysql_user = "username";
$mysql_pwd = "passwd";
$mysql_db = "database_name";
$mysql_port = 3306; // dit is de standaard MySQL port
$max_time = 600; // de timeout... Hoe lang is iemand non-actief totdat
// hij/zij uit de database wordt verwijderd? (in sec.)
/* Vanaf hier gaat de rest automatisch */
$db = @mysql_connect($mysql_host . ":" . $mysql_port,$mysql_user,$mysql_pwd)
or die ("Could not connect to MySQL server!");
mysql_select_db($mysql_db,$db)
or die ("Could not select database " . $mysql_db);
$tables_result = mysql_list_tables($mysql_db);
$TABLE_EXISTS = FALSE;
for ($c = 0; $c < mysql_num_rows($tables_result); $c++)
if (mysql_tablename($tables_result,$c) == "users_online") { $TABLE_EXISTS = TRUE; }
if (!$TABLE_EXISTS)
mysql_query("CREATE TABLE users_online (id INT NOT NULL auto_increment PRIMARY KEY, sess_id VARCHAR(100), time DATETIME)",$db);
session_start();
$id = session_id();
$query = mysql_query("SELECT * FROM users_online WHERE sess_id = '$id'",$db);
if (mysql_affected_rows() > 0)
mysql_query("UPDATE users_online SET time = now() WHERE sess_id = '$id'",$db);
else
mysql_query("INSERT INTO users_online VALUES(0,'$id',now())",$db);
$now = date("U") - $max_time; // $now = UNIX timestamp - $max_time
$now = date("Y-m-d H:i:s",$now);
mysql_query("DELETE FROM users_online WHERE time < '$now'",$db);
$count_query = mysql_query("SELECT COUNT(*) as TOTAL FROM users_online",$db);
$user_count = mysql_result($count_query,0,"TOTAL");
?>
<center>
Online</center>