]>
git.bts.cx Git - cx.git/blob - cx/lib/sessions.php
3 cx_require('lib', 'db.php');
4 cx_require('lib', 'setup.php');
6 function cx_sessions_create_session($user) {
7 $uid = sha1(random_bytes(100));
8 $update_time = $creation_time = time();
10 $sql = 'INSERT INTO sessions (
13 session_creation_time,
16 VALUES (?, ?, ?, ?, ?);';
17 cx_db_exec($sql, $uid, $user, $creation_time, $update_time, -1);
22 function cx_sessions_close_session($uid) {
25 $sql = 'UPDATE sessions
26 SET session_closed_time = ?
27 WHERE session_uid == ?;';
30 cx_db_exec($sql, $close_time, $uid);
33 function cx_sessions_active_session_user($uid, $lifetime) {
37 WHERE session_uid == ?
38 AND session_update_time >= ?
39 AND session_closed_time == -1
42 $update_time = time() - $lifetime;
44 foreach (cx_db_query($sql, $uid, $update_time) as $session) {
45 return $session['session_user_id'];
51 cx_setup_register(1, function() {
52 cx_db_exec('CREATE TABLE sessions (
53 session_id INTEGER PRIMARY KEY,
55 session_user_id INTEGER,
56 session_creation_time INTEGER,
57 session_update_time INTEGER,
58 session_closed_time INTEGER,
60 FOREIGN KEY(session_user_id) REFERENCES users(user_id))');