6 * Values: date : IP : data
7 * Already open sessions, e.g. interim xmlrpc requests are
8 * are treated specially. see write().
9 * To avoid deadlocks in the session.db3 access,
10 * the db is opened and closed for each access.
11 * @author: Reini Urban.
16 var $_backend_type = "dba";
18 function DbSession_dba(&$dbh, $table)
21 ini_set('session.save_handler', 'user');
22 session_module_name('user'); // new style
23 session_set_save_handler(array(&$this, 'open'),
24 array(&$this, 'close'),
25 array(&$this, 'read'),
26 array(&$this, 'write'),
27 array(&$this, 'destroy'),
49 $dba_handler = 'gdbm';
51 extract($DBParams); // overwrite the defaults
52 $dbfile = "$directory/$prefix" . 'session' . '.' . $dba_handler;
53 $dbh = new DbaDatabase($dbfile, 'c', $dba_handler);
59 function _disconnect()
61 if (isset($this->_dbh)) {
67 function open($save_path, $session_name)
69 $dbh = $this->_connect();
80 $dbh = $this->_connect();
81 $result = $dbh->get($id);
85 list(, , $packed) = explode(':', $result, 3);
87 if (strlen($packed) > 4000) {
88 trigger_error("Overlarge session data!", E_USER_WARNING);
90 //$res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/',"",$res);
95 function write($id, $sess_data)
97 if (defined("WIKI_XMLRPC") or defined("WIKI_SOAP")) return;
99 $dbh = $this->_connect();
101 $ip = $GLOBALS['request']->get('REMOTE_ADDR');
102 if (strlen($sess_data) > 4000) {
103 trigger_error("Overlarge session data!", E_USER_WARNING);
106 $dbh->set($id, $time . ':' . $ip . ':' . $sess_data);
107 $this->_disconnect();
111 function destroy($id)
113 $dbh = $this->_connect();
115 $this->_disconnect();
119 function gc($maxlifetime)
121 $dbh = $this->_connect();
122 $threshold = time() - $maxlifetime;
123 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
124 $result = $dbh->get($id);
125 list($date, ,) = explode(':', $result, 3);
126 if ($date < $threshold)
129 $this->_disconnect();
133 // WhoIsOnline support.
134 // TODO: ip-accesstime dynamic blocking API
135 function currentSessions()
138 $dbh = $this->_connect();
139 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
140 $result = $dbh->get($id);
141 list($date, $ip, $packed) = explode(':', $result, 3);
142 if (!$packed) continue;
143 // session_data contains the <variable name> + "|" + <packed string>
144 // we need just the wiki_user object (might be array as well)
145 if ($date < 908437560 or $date > 1588437560)
147 $user = strstr($packed, "wiki_user|");
148 $sessions[] = array('wiki_user' => substr($user, 10), // from "O:" onwards
152 $this->_disconnect();
161 // c-hanging-comment-ender-p: nil
162 // indent-tabs-mode: nil