2003-11-18 19:44:36 +00:00
|
|
|
<?php
|
2003-12-13 13:00:47 +00:00
|
|
|
// $Id$
|
2003-11-18 19:44:36 +00:00
|
|
|
|
2004-08-21 06:42:38 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* User session handling functions.
|
|
|
|
*/
|
|
|
|
|
2003-11-18 19:44:36 +00:00
|
|
|
/*** Session functions *****************************************************/
|
|
|
|
|
|
|
|
function sess_open($save_path, $session_name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sess_close() {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sess_read($key) {
|
|
|
|
global $user;
|
2005-03-01 20:15:10 +00:00
|
|
|
|
2005-12-31 11:50:47 +00:00
|
|
|
$result = db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", $key);
|
2003-11-18 23:37:48 +00:00
|
|
|
|
|
|
|
if (!db_num_rows($result)) {
|
2005-03-01 20:15:10 +00:00
|
|
|
db_query("INSERT INTO {sessions} (sid, uid, hostname, timestamp) VALUES ('%s', 0, '%s', %d)", $key, $_SERVER["REMOTE_ADDR"], time());
|
2004-11-07 21:53:55 +00:00
|
|
|
$result = db_query("SELECT u.* FROM {users} u WHERE u.uid = 0");
|
2003-11-18 23:37:48 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 19:44:36 +00:00
|
|
|
$user = db_fetch_object($result);
|
2004-01-13 19:25:37 +00:00
|
|
|
$user = drupal_unpack($user);
|
2004-05-10 20:34:25 +00:00
|
|
|
$user->roles = array();
|
|
|
|
|
|
|
|
$result = db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d", $user->uid);
|
|
|
|
|
|
|
|
while ($role = db_fetch_object($result)) {
|
|
|
|
$user->roles[$role->rid] = $role->name;
|
|
|
|
}
|
2003-11-18 19:44:36 +00:00
|
|
|
|
|
|
|
return !empty($user->session) ? $user->session : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function sess_write($key, $value) {
|
|
|
|
global $user;
|
|
|
|
|
2005-04-11 19:05:52 +00:00
|
|
|
db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, $user->cache, $_SERVER["REMOTE_ADDR"], $value, time(), $key);
|
2005-10-28 13:35:49 +00:00
|
|
|
if ($user->uid) {
|
|
|
|
db_query("UPDATE {users} SET access = %d WHERE uid = %d", time(), $user->uid);
|
|
|
|
}
|
2003-11-18 19:44:36 +00:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function sess_destroy($key) {
|
2005-08-10 20:42:54 +00:00
|
|
|
db_query("DELETE FROM {sessions} WHERE sid = '%s'", $key);
|
2003-11-18 19:44:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function sess_gc($lifetime) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
|
|
|
|
** value. For example, if you want user sessions to stay in your database
|
|
|
|
** for three weeks before deleting them, you need to set gc_maxlifetime
|
|
|
|
** to '1814400'. At that value, only after a user doesn't log in after
|
|
|
|
** three weeks (1814400 seconds) will his/her session be removed.
|
|
|
|
*/
|
|
|
|
db_query("DELETE FROM {sessions} WHERE timestamp < %d", time() - $lifetime);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-08-25 21:14:17 +00:00
|
|
|
|