diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-21 17:52:20 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-10-21 17:52:20 +0000 |
commit | 690aeeeae3b788009b6afb17bb59623e475ec06b (patch) | |
tree | 8061e6b5301281fe1241f3fba44942bb0753882c /engine/lib | |
parent | fa161bd35911c6220fd45ff05357da689118b1b3 (diff) | |
download | elgg-690aeeeae3b788009b6afb17bb59623e475ec06b.tar.gz elgg-690aeeeae3b788009b6afb17bb59623e475ec06b.tar.bz2 |
Database session code.
IMPORTANT NOTE:
The trigger for this is commented out, so old session code is used. There are serious problems with using the new code since it causes a chicken and egg problem with the upgrade script.
git-svn-id: https://code.elgg.org/elgg/trunk@2289 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/sessions.php | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index f6dbaa1a6..4e1a0a494 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -186,8 +186,11 @@ */
function session_init($event, $object_type, $object) {
- if (!is_db_installed()) return false;
-
+ if (!is_db_installed()) return false; + + // Use database for sessions + //session_set_save_handler("__elgg_session_open", "__elgg_session_close", "__elgg_session_read", "__elgg_session_write", "__elgg_session_destroy", "__elgg_session_gc"); +
session_name('Elgg');
session_start(); @@ -285,6 +288,76 @@ forward();
} }
+ + /** + * DB Based session handling code. + */ + function __elgg_session_open($save_path, $session_name) + { + return true; + } + + /** + * DB Based session handling code. + */ + function __elgg_session_close() + { + return true; + } + + /** + * DB Based session handling code. + */ + function __elgg_session_read($id) + { + global $CONFIG; + + $id = sanitise_string($id); + + $result = get_data("SELECT * from {$CONFIG->dbprefix}users_sessions where session='$id'"); + if ($result) + return $result->data; + + return ''; + } + + /** + * DB Based session handling code. + */ + function __elgg_session_write($id, $sess_data) + { + global $CONFIG; + + $id = sanitise_string($id); + $sess_data = sanitise_string($sess_data); + $time = time(); + + return (bool)insert_data("INSERT INTO {$CONFIG->dbprefix}users_sessions (session, ts, data) VALUES ('$id', '$time', '$sess_data') ON DUPLICATE set ts='$time', data='$sess_data'"); + } + + /** + * DB Based session handling code. + */ + function __elgg_session_destroy($id) + { + global $CONFIG; + + $id = sanitise_string($id); + + return (bool)delete_data("DELETE from {$CONFIG->dbprefix}users_sessions where session='$id'"); + } + + /** + * DB Based session handling code. + */ + function __elgg_session_gc($maxlifetime) + { + global $CONFIG; + + $life = time()-$maxlifetime; + + return (bool)delete_data("DELETE from {$CONFIG->dbprefix}users_sessions where ts<'$life'"); + } register_elgg_event_handler("boot","system","session_init",1);
|