function sess_write in Drupal 4
Same name and namespace in other branches
- 5 includes/session.inc \sess_write()
- 6 includes/session.inc \sess_write()
1 string reference to 'sess_write'
- _drupal_bootstrap in includes/
bootstrap.inc
File
- includes/
session.inc, line 54 - User session handling functions.
Code
function sess_write($key, $value) {
global $user;
$result = db_query("SELECT sid FROM {sessions} WHERE sid = '%s'", $key);
if (!db_num_rows($result)) {
// Only save session data when when the browser sends a cookie. This keeps
// crawlers out of session table. This improves speed up queries, reduces
// memory, and gives more useful statistics. We can't eliminate anonymous
// session table rows without breaking throttle module and "Who's Online"
// block.
if ($user->uid || $value || count($_COOKIE)) {
db_query("INSERT INTO {sessions} (sid, uid, cache, hostname, session, timestamp) VALUES ('%s', %d, %d, '%s', '%s', %d)", $key, $user->uid, $user->cache, $_SERVER["REMOTE_ADDR"], $value, time());
}
}
else {
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);
// TODO: this can be an expensive query. Perhaps only execute it every x minutes. Requires investigation into cache expiration.
if ($user->uid) {
db_query("UPDATE {users} SET access = %d WHERE uid = %d", time(), $user->uid);
}
}
return TRUE;
}