diff options
-rw-r--r-- | engine/lib/sessions.php | 77 | ||||
-rw-r--r-- | engine/schema/mysql.sql | 12 | ||||
-rw-r--r-- | engine/schema/upgrades/2008102101.sql | 11 | ||||
-rw-r--r-- | version.php | 2 |
4 files changed, 99 insertions, 3 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);
diff --git a/engine/schema/mysql.sql b/engine/schema/mysql.sql index bb8646858..f82a276d6 100644 --- a/engine/schema/mysql.sql +++ b/engine/schema/mysql.sql @@ -270,6 +270,18 @@ CREATE TABLE `prefix_hmac_cache` ( KEY `ts` (`ts`)
) ENGINE=MEMORY;
+-- PHP Session storage
+CREATE TABLE `prefix_users_sessions` (
+ `id` int(11) NOT NULL auto_increment,
+ `session` varchar(255) NOT NULL,
+ `ts` int(11) unsigned NOT NULL default '0',
+ `data` mediumtext,
+
+ PRIMARY KEY (`id`),
+ KEY `session` (`session`),
+ KEY `expires` (`expires`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
-- Datalists for things like db version
CREATE TABLE `prefix_datalists` (
`name` varchar(32) NOT NULL,
diff --git a/engine/schema/upgrades/2008102101.sql b/engine/schema/upgrades/2008102101.sql new file mode 100644 index 000000000..815fa05de --- /dev/null +++ b/engine/schema/upgrades/2008102101.sql @@ -0,0 +1,11 @@ + +CREATE TABLE IF NOT EXISTS `prefix_users_sessions` ( + `id` int(11) NOT NULL auto_increment, + `session` varchar(255) NOT NULL, + `ts` int(11) unsigned NOT NULL default '0', + `data` mediumtext, + + PRIMARY KEY (`id`), + KEY `session` (`session`), + KEY `expires` (`expires`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8;
\ No newline at end of file diff --git a/version.php b/version.php index 0ab5ce35e..de5ca8f02 100644 --- a/version.php +++ b/version.php @@ -13,7 +13,7 @@ * @link http://elgg.org/
*/
- $version = 2008101701; // YYYYMMDD = Elgg Date
+ $version = 2008102101; // YYYYMMDD = Elgg Date
// XX = Interim incrementer
$release = '1.09'; // Human-friendly version name
|