00001 <?php
00002
00003
00009 function sess_open($save_path, $session_name) {
00010 return TRUE;
00011 }
00012
00013 function sess_close() {
00014 return TRUE;
00015 }
00016
00017 function sess_read($key) {
00018 global $user;
00019
00020
00021
00022
00023 register_shutdown_function('session_write_close');
00024
00025
00026 if (!isset($_COOKIE[session_name()])) {
00027 $user = drupal_anonymous_user();
00028 return '';
00029 }
00030
00031
00032 $user = db_fetch_object(db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.sid = '%s'", $key));
00033
00034
00035 if ($user && $user->uid > 0) {
00036
00037 $user = drupal_unpack($user);
00038
00039
00040 $user->roles = array();
00041 $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
00042 $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);
00043 while ($role = db_fetch_object($result)) {
00044 $user->roles[$role->rid] = $role->name;
00045 }
00046 }
00047
00048 else {
00049 $session = isset($user->session) ? $user->session : '';
00050 $user = drupal_anonymous_user($session);
00051 }
00052
00053 return $user->session;
00054 }
00055
00056 function sess_write($key, $value) {
00057 global $user;
00058
00059
00060
00061 if (!session_save_session() || (empty($_COOKIE[session_name()]) && empty($value))) {
00062 return TRUE;
00063 }
00064
00065 $result = db_result(db_query("SELECT COUNT(*) FROM {sessions} WHERE sid = '%s'", $key));
00066
00067 if (!$result) {
00068
00069
00070
00071
00072 if ($user->uid || $value || count($_COOKIE)) {
00073 db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, isset($user->cache) ? $user->cache : '', ip_address(), $value, time());
00074 }
00075 }
00076 else {
00077 db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, isset($user->cache) ? $user->cache : '', ip_address(), $value, time(), $key);
00078
00079
00080
00081 if ($user->uid && time() - $user->access > variable_get('session_write_interval', 180)) {
00082 db_query("UPDATE {users} SET access = %d WHERE uid = %d", time(), $user->uid);
00083 }
00084 }
00085
00086 return TRUE;
00087 }
00088
00092 function sess_regenerate() {
00093 $old_session_id = session_id();
00094 session_regenerate_id();
00095 db_query("UPDATE {sessions} SET sid = '%s' WHERE sid = '%s'", session_id(), $old_session_id);
00096 }
00097
00111 function sess_count($timestamp = 0, $anonymous = true) {
00112 $query = $anonymous ? ' AND uid = 0' : ' AND uid > 0';
00113 return db_result(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d' . $query, $timestamp));
00114 }
00115
00122 function sess_destroy_sid($sid) {
00123 db_query("DELETE FROM {sessions} WHERE sid = '%s'", $sid);
00124 }
00125
00132 function sess_destroy_uid($uid) {
00133 db_query('DELETE FROM {sessions} WHERE uid = %d', $uid);
00134 }
00135
00136 function sess_gc($lifetime) {
00137
00138
00139
00140
00141
00142 db_query("DELETE FROM {sessions} WHERE timestamp < %d", time() - $lifetime);
00143
00144 return TRUE;
00145 }
00146
00159 function session_save_session($status = NULL) {
00160 static $save_session = TRUE;
00161 if (isset($status)) {
00162 $save_session = $status;
00163 }
00164 return ($save_session);
00165 }