1 <?php rcs_id('$Id: dba.php,v 1.3 2005-08-07 10:49:57 rurban Exp $');
6 * Values: date : IP : data
7 * @author: Reini Urban.
12 var $_backend_type = "dba";
14 function DbSession_dba (&$dbh, $table) {
16 ini_set('session.save_handler','user');
17 session_module_name('user'); // new style
18 session_set_save_handler(array(&$this, 'open'),
19 array(&$this, 'close'),
20 array(&$this, 'read'),
21 array(&$this, 'write'),
22 array(&$this, 'destroy'),
27 function quote($str) { return $str; }
28 function query($sql) { return false; }
36 $dba_handler = 'gdbm';
40 $dbfile = "$directory/$prefix" . 'session' . '.' . $dba_handler;
41 $dbh = new DbaDatabase($dbfile, 'c', $dba_handler);
47 function _disconnect() {
48 if (isset($this->_dbh))
52 function open ($save_path, $session_name) {
53 $dbh = $this->_connect();
63 $dbh = $this->_connect();
64 $result = $dbh->get($id);
68 list(,,$packed) = explode(':', $result, 3);
69 // $this->_disconnect();
70 if (strlen($packed) > 4000) {
71 trigger_error("Overlarge session data!", E_USER_WARNING);
73 //$res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/',"",$res);
78 function write ($id, $sess_data) {
79 $dbh = $this->_connect();
81 $ip = $GLOBALS['request']->get('REMOTE_ADDR');
82 if (strlen($sess_data) > 4000) {
83 trigger_error("Overlarge session data!", E_USER_WARNING);
86 $dbh->set($id, $time.':'.$ip.':'.$sess_data);
87 //$this->_disconnect();
91 function destroy ($id) {
92 $dbh = $this->_connect();
94 //$this->_disconnect();
98 function gc ($maxlifetime) {
99 $dbh = $this->_connect();
100 $threshold = time() - $maxlifetime;
101 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
102 $result = $dbh->get($id);
103 list($date,,) = explode(':', $result, 3);
104 if ($date < $threshold)
107 //$this->_disconnect();
111 // WhoIsOnline support.
112 // TODO: ip-accesstime dynamic blocking API
113 function currentSessions() {
115 $dbh = &$this->_connect();
116 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
117 $result = $dbh->get($id);
118 list($date,$ip,$packed) = explode(':', $result, 3);
119 if (!$packed) continue;
120 // session_data contains the <variable name> + "|" + <packed string>
121 // we need just the wiki_user object (might be array as well)
122 if ($date < 908437560 or $date > 1588437560)
124 $user = strstr($packed, "wiki_user|");
125 $sessions[] = array('wiki_user' => substr($user,10), // from "O:" onwards
129 $this->_disconnect();
134 // $Log: not supported by cvs2svn $
135 // Revision 1.2 2005/08/07 10:07:55 rurban
136 // dba simplification: use default timeout
138 // Revision 1.1 2005/02/11 14:41:40 rurban
139 // seperate DbSession classes: less memory, a bit slower
146 // c-hanging-comment-ender-p: nil
147 // indent-tabs-mode: nil