aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-21 17:52:20 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-10-21 17:52:20 +0000
commit690aeeeae3b788009b6afb17bb59623e475ec06b (patch)
tree8061e6b5301281fe1241f3fba44942bb0753882c /engine
parentfa161bd35911c6220fd45ff05357da689118b1b3 (diff)
downloadelgg-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')
-rw-r--r--engine/lib/sessions.php77
-rw-r--r--engine/schema/mysql.sql12
-rw-r--r--engine/schema/upgrades/2008102101.sql11
3 files changed, 98 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);
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