Documentation TYPO3 par Ameos |
00001 <?php 00002 00003 00004 /* 00005 V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. 00006 Contributed by Ross Smith (adodb@netebb.com). 00007 Released under both BSD license and Lesser GPL library license. 00008 Whenever there is any discrepancy between the two licenses, 00009 the BSD license will take precedence. 00010 Set tabs to 4 for best viewing. 00011 00012 00013 */ 00014 00015 /* 00016 00017 CREATE Table SCripts 00018 00019 Oracle 00020 ====== 00021 00022 CREATE TABLE SESSIONS2 00023 ( 00024 SESSKEY VARCHAR2(48 BYTE) NOT NULL, 00025 EXPIRY DATE NOT NULL, 00026 EXPIREREF VARCHAR2(200 BYTE), 00027 CREATED DATE NOT NULL, 00028 MODIFIED DATE NOT NULL, 00029 SESSDATA CLOB, 00030 PRIMARY KEY(SESSKEY) 00031 ); 00032 00033 00034 CREATE INDEX SESS2_EXPIRY ON SESSIONS2(EXPIRY); 00035 CREATE UNIQUE INDEX SESS2_PK ON SESSIONS2(SESSKEY); 00036 CREATE INDEX SESS2_EXP_REF ON SESSIONS2(EXPIREREF); 00037 00038 00039 00040 MySQL 00041 ===== 00042 00043 CREATE TABLE sessions2( 00044 sesskey VARCHAR( 64 ) NOT NULL DEFAULT '', 00045 expiry TIMESTAMP NOT NULL , 00046 expireref VARCHAR( 250 ) DEFAULT '', 00047 created TIMESTAMP NOT NULL , 00048 modified TIMESTAMP NOT NULL , 00049 sessdata LONGTEXT DEFAULT '', 00050 PRIMARY KEY ( sesskey ) , 00051 INDEX sess2_expiry( expiry ), 00052 INDEX sess2_expireref( expireref ) 00053 ) 00054 00055 00056 */ 00057 00058 if (!defined('_ADODB_LAYER')) { 00059 require realpath(dirname(__FILE__) . '/../adodb.inc.php'); 00060 } 00061 00062 if (defined('ADODB_SESSION')) return 1; 00063 00064 define('ADODB_SESSION', dirname(__FILE__)); 00065 define('ADODB_SESSION2', ADODB_SESSION); 00066 00067 /* 00068 Unserialize session data manually. See http://phplens.com/lens/lensforum/msgs.php?id=9821 00069 00070 From Kerr Schere, to unserialize session data stored via ADOdb. 00071 1. Pull the session data from the db and loop through it. 00072 2. Inside the loop, you will need to urldecode the data column. 00073 3. After urldecode, run the serialized string through this function: 00074 00075 */ 00076 function adodb_unserialize( $serialized_string ) 00077 { 00078 $variables = array( ); 00079 $a = preg_split( "/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE ); 00080 for( $i = 0; $i < count( $a ); $i = $i+2 ) { 00081 $variables[$a[$i]] = unserialize( $a[$i+1] ); 00082 } 00083 return( $variables ); 00084 } 00085 00086 /* 00087 Thanks Joe Li. See http://phplens.com/lens/lensforum/msgs.php?id=11487&x=1 00088 Since adodb 4.61. 00089 */ 00090 function adodb_session_regenerate_id() 00091 { 00092 $conn =& ADODB_Session::_conn(); 00093 if (!$conn) return false; 00094 00095 $old_id = session_id(); 00096 if (function_exists('session_regenerate_id')) { 00097 session_regenerate_id(); 00098 } else { 00099 session_id(md5(uniqid(rand(), true))); 00100 $ck = session_get_cookie_params(); 00101 setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); 00102 //@session_start(); 00103 } 00104 $new_id = session_id(); 00105 $ok =& $conn->Execute('UPDATE '. ADODB_Session::table(). ' SET sesskey='. $conn->qstr($new_id). ' WHERE sesskey='.$conn->qstr($old_id)); 00106 00107 /* it is possible that the update statement fails due to a collision */ 00108 if (!$ok) { 00109 session_id($old_id); 00110 if (empty($ck)) $ck = session_get_cookie_params(); 00111 setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); 00112 return false; 00113 } 00114 00115 return true; 00116 } 00117 00118 /* 00119 Generate database table for session data 00120 @see http://phplens.com/lens/lensforum/msgs.php?id=12280 00121 @return 0 if failure, 1 if errors, 2 if successful. 00122 @author Markus Staab http://www.public-4u.de 00123 */ 00124 function adodb_session_create_table($schemaFile=null,$conn = null) 00125 { 00126 // set default values 00127 if ($schemaFile===null) $schemaFile = ADODB_SESSION . '/session_schema2.xml'; 00128 if ($conn===null) $conn =& ADODB_Session::_conn(); 00129 00130 if (!$conn) return 0; 00131 00132 $schema = new adoSchema($conn); 00133 $schema->ParseSchema($schemaFile); 00134 return $schema->ExecuteSchema(); 00135 } 00136 00140 class ADODB_Session { 00142 // getter/setter methods 00144 00145 /* 00146 00147 function Lock($lock=null) 00148 { 00149 static $_lock = false; 00150 00151 if (!is_null($lock)) $_lock = $lock; 00152 return $lock; 00153 } 00154 */ 00157 function driver($driver = null) 00158 { 00159 static $_driver = 'mysql'; 00160 static $set = false; 00161 00162 if (!is_null($driver)) { 00163 $_driver = trim($driver); 00164 $set = true; 00165 } elseif (!$set) { 00166 // backwards compatibility 00167 if (isset($GLOBALS['ADODB_SESSION_DRIVER'])) { 00168 return $GLOBALS['ADODB_SESSION_DRIVER']; 00169 } 00170 } 00171 00172 return $_driver; 00173 } 00174 00177 function host($host = null) { 00178 static $_host = 'localhost'; 00179 static $set = false; 00180 00181 if (!is_null($host)) { 00182 $_host = trim($host); 00183 $set = true; 00184 } elseif (!$set) { 00185 // backwards compatibility 00186 if (isset($GLOBALS['ADODB_SESSION_CONNECT'])) { 00187 return $GLOBALS['ADODB_SESSION_CONNECT']; 00188 } 00189 } 00190 00191 return $_host; 00192 } 00193 00196 function user($user = null) 00197 { 00198 static $_user = 'root'; 00199 static $set = false; 00200 00201 if (!is_null($user)) { 00202 $_user = trim($user); 00203 $set = true; 00204 } elseif (!$set) { 00205 // backwards compatibility 00206 if (isset($GLOBALS['ADODB_SESSION_USER'])) { 00207 return $GLOBALS['ADODB_SESSION_USER']; 00208 } 00209 } 00210 00211 return $_user; 00212 } 00213 00216 function password($password = null) 00217 { 00218 static $_password = ''; 00219 static $set = false; 00220 00221 if (!is_null($password)) { 00222 $_password = $password; 00223 $set = true; 00224 } elseif (!$set) { 00225 // backwards compatibility 00226 if (isset($GLOBALS['ADODB_SESSION_PWD'])) { 00227 return $GLOBALS['ADODB_SESSION_PWD']; 00228 } 00229 } 00230 00231 return $_password; 00232 } 00233 00236 function database($database = null) 00237 { 00238 static $_database = ''; 00239 static $set = false; 00240 00241 if (!is_null($database)) { 00242 $_database = trim($database); 00243 $set = true; 00244 } elseif (!$set) { 00245 // backwards compatibility 00246 if (isset($GLOBALS['ADODB_SESSION_DB'])) { 00247 return $GLOBALS['ADODB_SESSION_DB']; 00248 } 00249 } 00250 return $_database; 00251 } 00252 00255 function persist($persist = null) 00256 { 00257 static $_persist = true; 00258 00259 if (!is_null($persist)) { 00260 $_persist = trim($persist); 00261 } 00262 00263 return $_persist; 00264 } 00265 00268 function lifetime($lifetime = null) 00269 { 00270 static $_lifetime; 00271 static $set = false; 00272 00273 if (!is_null($lifetime)) { 00274 $_lifetime = (int) $lifetime; 00275 $set = true; 00276 } elseif (!$set) { 00277 // backwards compatibility 00278 if (isset($GLOBALS['ADODB_SESS_LIFE'])) { 00279 return $GLOBALS['ADODB_SESS_LIFE']; 00280 } 00281 } 00282 if (!$_lifetime) { 00283 $_lifetime = ini_get('session.gc_maxlifetime'); 00284 if ($_lifetime <= 1) { 00285 // bug in PHP 4.0.3 pl 1 -- how about other versions? 00286 //print "<h3>Session Error: PHP.INI setting <i>session.gc_maxlifetime</i>not set: $lifetime</h3>"; 00287 $_lifetime = 1440; 00288 } 00289 } 00290 00291 return $_lifetime; 00292 } 00293 00296 function debug($debug = null) 00297 { 00298 static $_debug = false; 00299 static $set = false; 00300 00301 if (!is_null($debug)) { 00302 $_debug = (bool) $debug; 00303 00304 $conn = ADODB_Session::_conn(); 00305 if ($conn) { 00306 $conn->debug = $_debug; 00307 } 00308 $set = true; 00309 } elseif (!$set) { 00310 // backwards compatibility 00311 if (isset($GLOBALS['ADODB_SESS_DEBUG'])) { 00312 return $GLOBALS['ADODB_SESS_DEBUG']; 00313 } 00314 } 00315 00316 return $_debug; 00317 } 00318 00321 function expireNotify($expire_notify = null) 00322 { 00323 static $_expire_notify; 00324 static $set = false; 00325 00326 if (!is_null($expire_notify)) { 00327 $_expire_notify = $expire_notify; 00328 $set = true; 00329 } elseif (!$set) { 00330 // backwards compatibility 00331 if (isset($GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY'])) { 00332 return $GLOBALS['ADODB_SESSION_EXPIRE_NOTIFY']; 00333 } 00334 } 00335 00336 return $_expire_notify; 00337 } 00338 00341 function table($table = null) 00342 { 00343 static $_table = 'sessions2'; 00344 static $set = false; 00345 00346 if (!is_null($table)) { 00347 $_table = trim($table); 00348 $set = true; 00349 } elseif (!$set) { 00350 // backwards compatibility 00351 if (isset($GLOBALS['ADODB_SESSION_TBL'])) { 00352 return $GLOBALS['ADODB_SESSION_TBL']; 00353 } 00354 } 00355 00356 return $_table; 00357 } 00358 00361 function optimize($optimize = null) 00362 { 00363 static $_optimize = false; 00364 static $set = false; 00365 00366 if (!is_null($optimize)) { 00367 $_optimize = (bool) $optimize; 00368 $set = true; 00369 } elseif (!$set) { 00370 // backwards compatibility 00371 if (defined('ADODB_SESSION_OPTIMIZE')) { 00372 return true; 00373 } 00374 } 00375 00376 return $_optimize; 00377 } 00378 00381 function syncSeconds($sync_seconds = null) { 00382 //echo ("<p>WARNING: ADODB_SESSION::syncSeconds is longer used, please remove this function for your code</p>"); 00383 00384 return 0; 00385 } 00386 00389 function clob($clob = null) { 00390 static $_clob = false; 00391 static $set = false; 00392 00393 if (!is_null($clob)) { 00394 $_clob = strtolower(trim($clob)); 00395 $set = true; 00396 } elseif (!$set) { 00397 // backwards compatibility 00398 if (isset($GLOBALS['ADODB_SESSION_USE_LOBS'])) { 00399 return $GLOBALS['ADODB_SESSION_USE_LOBS']; 00400 } 00401 } 00402 00403 return $_clob; 00404 } 00405 00408 function dataFieldName($data_field_name = null) { 00409 //echo ("<p>WARNING: ADODB_SESSION::dataFieldName() is longer used, please remove this function for your code</p>"); 00410 return ''; 00411 } 00412 00415 function filter($filter = null) { 00416 static $_filter = array(); 00417 00418 if (!is_null($filter)) { 00419 if (!is_array($filter)) { 00420 $filter = array($filter); 00421 } 00422 $_filter = $filter; 00423 } 00424 00425 return $_filter; 00426 } 00427 00430 function encryptionKey($encryption_key = null) { 00431 static $_encryption_key = 'CRYPTED ADODB SESSIONS ROCK!'; 00432 00433 if (!is_null($encryption_key)) { 00434 $_encryption_key = $encryption_key; 00435 } 00436 00437 return $_encryption_key; 00438 } 00439 00441 // private methods 00443 00446 function &_conn($conn=null) { 00447 return $GLOBALS['ADODB_SESS_CONN']; 00448 } 00449 00452 function _crc($crc = null) { 00453 static $_crc = false; 00454 00455 if (!is_null($crc)) { 00456 $_crc = $crc; 00457 } 00458 00459 return $_crc; 00460 } 00461 00464 function _init() { 00465 session_module_name('user'); 00466 session_set_save_handler( 00467 array('ADODB_Session', 'open'), 00468 array('ADODB_Session', 'close'), 00469 array('ADODB_Session', 'read'), 00470 array('ADODB_Session', 'write'), 00471 array('ADODB_Session', 'destroy'), 00472 array('ADODB_Session', 'gc') 00473 ); 00474 } 00475 00476 00479 function _sessionKey() { 00480 // use this function to create the encryption key for crypted sessions 00481 // crypt the used key, ADODB_Session::encryptionKey() as key and session_id() as salt 00482 return crypt(ADODB_Session::encryptionKey(), session_id()); 00483 } 00484 00487 function _dumprs($rs) { 00488 $conn =& ADODB_Session::_conn(); 00489 $debug = ADODB_Session::debug(); 00490 00491 if (!$conn) { 00492 return; 00493 } 00494 00495 if (!$debug) { 00496 return; 00497 } 00498 00499 if (!$rs) { 00500 echo "<br />\$rs is null or false<br />\n"; 00501 return; 00502 } 00503 00504 //echo "<br />\nAffected_Rows=",$conn->Affected_Rows(),"<br />\n"; 00505 00506 if (!is_object($rs)) { 00507 return; 00508 } 00509 00510 require_once ADODB_SESSION.'/../tohtml.inc.php'; 00511 rs2html($rs); 00512 } 00513 00515 // public methods 00517 00518 function config($driver, $host, $user, $password, $database=false,$options=false) 00519 { 00520 ADODB_Session::driver($driver); 00521 ADODB_Session::host($host); 00522 ADODB_Session::user($user); 00523 ADODB_Session::password($password); 00524 ADODB_Session::database($database); 00525 00526 if ($driver == 'oci8' || $driver == 'oci8po') $options['lob'] = 'CLOB'; 00527 00528 if (isset($options['table'])) ADODB_Session::table($options['table']); 00529 if (isset($options['lob'])) ADODB_Session::clob($options['lob']); 00530 if (isset($options['debug'])) ADODB_Session::debug($options['debug']); 00531 } 00532 00538 function open($save_path, $session_name, $persist = null) 00539 { 00540 $conn =& ADODB_Session::_conn(); 00541 00542 if ($conn) { 00543 return true; 00544 } 00545 00546 $database = ADODB_Session::database(); 00547 $debug = ADODB_Session::debug(); 00548 $driver = ADODB_Session::driver(); 00549 $host = ADODB_Session::host(); 00550 $password = ADODB_Session::password(); 00551 $user = ADODB_Session::user(); 00552 00553 if (!is_null($persist)) { 00554 ADODB_Session::persist($persist); 00555 } else { 00556 $persist = ADODB_Session::persist(); 00557 } 00558 00559 # these can all be defaulted to in php.ini 00560 # assert('$database'); 00561 # assert('$driver'); 00562 # assert('$host'); 00563 00564 $conn =& ADONewConnection($driver); 00565 00566 if ($debug) { 00567 $conn->debug = true; 00568 ADOConnection::outp( " driver=$driver user=$user db=$database "); 00569 } 00570 00571 if ($persist) { 00572 switch($persist) { 00573 default: 00574 case 'P': $ok = $conn->PConnect($host, $user, $password, $database); break; 00575 case 'C': $ok = $conn->Connect($host, $user, $password, $database); break; 00576 case 'N': $ok = $conn->NConnect($host, $user, $password, $database); break; 00577 } 00578 } else { 00579 $ok = $conn->Connect($host, $user, $password, $database); 00580 } 00581 00582 if ($ok) $GLOBALS['ADODB_SESS_CONN'] =& $conn; 00583 else 00584 ADOConnection::outp('<p>Session: connection failed</p>', false); 00585 00586 00587 return $ok; 00588 } 00589 00593 function close() 00594 { 00595 /* 00596 $conn =& ADODB_Session::_conn(); 00597 if ($conn) $conn->Close(); 00598 */ 00599 return true; 00600 } 00601 00602 /* 00603 Slurp in the session variables and return the serialized string 00604 */ 00605 function read($key) 00606 { 00607 $conn =& ADODB_Session::_conn(); 00608 $filter = ADODB_Session::filter(); 00609 $table = ADODB_Session::table(); 00610 00611 if (!$conn) { 00612 return ''; 00613 } 00614 00615 //assert('$table'); 00616 00617 $qkey = $conn->quote($key); 00618 $binary = $conn->dataProvider === 'mysql' ? '' : ''; 00619 00620 $sql = "SELECT sessdata FROM $table WHERE sesskey = $binary $qkey AND expiry >= " . $conn->sysTimeStamp; 00621 /* Lock code does not work as it needs to hold transaction within whole page, and we don't know if 00622 developer has commited elsewhere... :( 00623 */ 00624 #if (ADODB_Session::Lock()) 00625 # $rs =& $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), sessdata); 00626 #else 00627 00628 $rs =& $conn->Execute($sql); 00629 //ADODB_Session::_dumprs($rs); 00630 if ($rs) { 00631 if ($rs->EOF) { 00632 $v = ''; 00633 } else { 00634 $v = reset($rs->fields); 00635 $filter = array_reverse($filter); 00636 foreach ($filter as $f) { 00637 if (is_object($f)) { 00638 $v = $f->read($v, ADODB_Session::_sessionKey()); 00639 } 00640 } 00641 $v = rawurldecode($v); 00642 } 00643 00644 $rs->Close(); 00645 00646 ADODB_Session::_crc(strlen($v) . crc32($v)); 00647 return $v; 00648 } 00649 00650 return ''; 00651 } 00652 00658 function write($key, $val) 00659 { 00660 global $ADODB_SESSION_READONLY; 00661 00662 if (!empty($ADODB_SESSION_READONLY)) return; 00663 00664 $clob = ADODB_Session::clob(); 00665 $conn =& ADODB_Session::_conn(); 00666 $crc = ADODB_Session::_crc(); 00667 $debug = ADODB_Session::debug(); 00668 $driver = ADODB_Session::driver(); 00669 $expire_notify = ADODB_Session::expireNotify(); 00670 $filter = ADODB_Session::filter(); 00671 $lifetime = ADODB_Session::lifetime(); 00672 $table = ADODB_Session::table(); 00673 00674 if (!$conn) { 00675 return false; 00676 } 00677 00678 $sysTimeStamp = $conn->sysTimeStamp; 00679 00680 //assert('$table'); 00681 00682 $expiry = $conn->OffsetDate($lifetime/(24*3600),$sysTimeStamp); 00683 00684 $binary = $conn->dataProvider === 'mysql' ? '' : ''; 00685 00686 // crc32 optimization since adodb 2.1 00687 // now we only update expiry date, thx to sebastian thom in adodb 2.32 00688 if ($crc !== false && $crc == (strlen($val) . crc32($val))) { 00689 if ($debug) { 00690 echo '<p>Session: Only updating date - crc32 not changed</p>'; 00691 } 00692 00693 $expirevar = ''; 00694 if ($expire_notify) { 00695 $var = reset($expire_notify); 00696 global $$var; 00697 if (isset($$var)) { 00698 $expirevar = $$var; 00699 } 00700 } 00701 00702 00703 $sql = "UPDATE $table SET expiry = $expiry ,expireref=".$conn->Param('0').", modified = $sysTimeStamp WHERE $binary sesskey = ".$conn->Param('1')." AND expiry >= $sysTimeStamp"; 00704 $rs =& $conn->Execute($sql,array($expirevar,$key)); 00705 return true; 00706 } 00707 $val = rawurlencode($val); 00708 foreach ($filter as $f) { 00709 if (is_object($f)) { 00710 $val = $f->write($val, ADODB_Session::_sessionKey()); 00711 } 00712 } 00713 00714 $expireref = ''; 00715 if ($expire_notify) { 00716 $var = reset($expire_notify); 00717 global $$var; 00718 if (isset($$var)) { 00719 $expireref = $$var; 00720 } 00721 } 00722 00723 if (!$clob) { // no lobs, simply use replace() 00724 $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".$conn->Param(0),array($key)); 00725 if ($rs) $rs->Close(); 00726 00727 if ($rs && reset($rs->fields) > 0) { 00728 $sql = "UPDATE $table SET expiry=$expiry, sessdata=".$conn->Param(0).", expireref= ".$conn->Param(1).",modified=$sysTimeStamp WHERE sesskey = ".$conn->Param('2'); 00729 00730 } else { 00731 $sql = "INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified) 00732 VALUES ($expiry,".$conn->Param('0').", ". $conn->Param('1').", ".$conn->Param('2').", $sysTimeStamp, $sysTimeStamp)"; 00733 } 00734 00735 00736 $rs =& $conn->Execute($sql,array($val,$expireref,$key)); 00737 00738 } else { 00739 // what value shall we insert/update for lob row? 00740 switch ($driver) { 00741 // empty_clob or empty_lob for oracle dbs 00742 case 'oracle': 00743 case 'oci8': 00744 case 'oci8po': 00745 case 'oci805': 00746 $lob_value = sprintf('empty_%s()', strtolower($clob)); 00747 break; 00748 00749 // null for all other 00750 default: 00751 $lob_value = 'null'; 00752 break; 00753 } 00754 00755 $conn->StartTrans(); 00756 00757 $rs =& $conn->Execute("SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".$conn->Param(0),array($key)); 00758 if ($rs) $rs->Close(); 00759 00760 if ($rs && reset($rs->fields) > 0) { 00761 $sql = "UPDATE $table SET expiry=$expiry, sessdata=$lob_value, expireref= ".$conn->Param(0).",modified=$sysTimeStamp WHERE sesskey = ".$conn->Param('1'); 00762 00763 } else { 00764 $sql = "INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified) 00765 VALUES ($expiry,$lob_value, ". $conn->Param('0').", ".$conn->Param('1').", $sysTimeStamp, $sysTimeStamp)"; 00766 } 00767 00768 $rs =& $conn->Execute($sql,array($expireref,$key)); 00769 00770 $qkey = $conn->qstr($key); 00771 $rs2 =& $conn->UpdateBlob($table, 'sessdata', $val, " sesskey=$qkey", strtoupper($clob)); 00772 $rs = $conn->CompleteTrans(); 00773 00774 00775 } 00776 00777 if (!$rs) { 00778 ADOConnection::outp('<p>Session Replace: ' . $conn->ErrorMsg() . '</p>', false); 00779 return false; 00780 } else { 00781 // bug in access driver (could be odbc?) means that info is not committed 00782 // properly unless select statement executed in Win2000 00783 if ($conn->databaseType == 'access') { 00784 $sql = "SELECT sesskey FROM $table WHERE $binary sesskey = $qkey"; 00785 $rs =& $conn->Execute($sql); 00786 ADODB_Session::_dumprs($rs); 00787 if ($rs) { 00788 $rs->Close(); 00789 } 00790 } 00791 }/* 00792 if (ADODB_Session::Lock()) { 00793 $conn->CommitTrans(); 00794 }*/ 00795 return $rs ? true : false; 00796 } 00797 00800 function destroy($key) { 00801 $conn =& ADODB_Session::_conn(); 00802 $table = ADODB_Session::table(); 00803 $expire_notify = ADODB_Session::expireNotify(); 00804 00805 if (!$conn) { 00806 return false; 00807 } 00808 00809 //assert('$table'); 00810 00811 $qkey = $conn->quote($key); 00812 $binary = $conn->dataProvider === 'mysql' ? '' : ''; 00813 00814 if ($expire_notify) { 00815 reset($expire_notify); 00816 $fn = next($expire_notify); 00817 $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); 00818 $sql = "SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey"; 00819 $rs =& $conn->Execute($sql); 00820 ADODB_Session::_dumprs($rs); 00821 $conn->SetFetchMode($savem); 00822 if (!$rs) { 00823 return false; 00824 } 00825 if (!$rs->EOF) { 00826 $ref = $rs->fields[0]; 00827 $key = $rs->fields[1]; 00828 //assert('$ref'); 00829 //assert('$key'); 00830 $fn($ref, $key); 00831 } 00832 $rs->Close(); 00833 } 00834 00835 $sql = "DELETE FROM $table WHERE $binary sesskey = $qkey"; 00836 $rs =& $conn->Execute($sql); 00837 ADODB_Session::_dumprs($rs); 00838 if ($rs) { 00839 $rs->Close(); 00840 } 00841 00842 return $rs ? true : false; 00843 } 00844 00847 function gc($maxlifetime) 00848 { 00849 $conn =& ADODB_Session::_conn(); 00850 $debug = ADODB_Session::debug(); 00851 $expire_notify = ADODB_Session::expireNotify(); 00852 $optimize = ADODB_Session::optimize(); 00853 $table = ADODB_Session::table(); 00854 00855 if (!$conn) { 00856 return false; 00857 } 00858 00859 //assert('$table'); 00860 00861 $time = $conn->sysTimeStamp; 00862 $binary = $conn->dataProvider === 'mysql' ? '' : ''; 00863 00864 if ($expire_notify) { 00865 reset($expire_notify); 00866 $fn = next($expire_notify); 00867 $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); 00868 $sql = "SELECT expireref, sesskey FROM $table WHERE expiry < $time"; 00869 $rs =& $conn->Execute($sql); 00870 ADODB_Session::_dumprs($rs); 00871 $conn->SetFetchMode($savem); 00872 if ($rs) { 00873 $conn->StartTrans(); 00874 $keys = array(); 00875 while (!$rs->EOF) { 00876 $ref = $rs->fields[0]; 00877 $key = $rs->fields[1]; 00878 $fn($ref, $key); 00879 $del = $conn->Execute("DELETE FROM $table WHERE sesskey=".$conn->Param('0'),array($key)); 00880 $rs->MoveNext(); 00881 } 00882 $rs->Close(); 00883 00884 $conn->CompleteTrans(); 00885 } 00886 } else { 00887 00888 if (0) { 00889 $sql = "SELECT sesskey FROM $table WHERE expiry < $time"; 00890 $arr =& $conn->GetAll($sql); 00891 foreach ($arr as $row) { 00892 $sql2 = "DELETE FROM $table WHERE sesskey=".$conn->Param('0'); 00893 $conn->Execute($sql2,array($row[0])); 00894 } 00895 } else { 00896 $sql = "DELETE FROM $table WHERE expiry < $time"; 00897 $rs =& $conn->Execute($sql); 00898 ADODB_Session::_dumprs($rs); 00899 if ($rs) $rs->Close(); 00900 } 00901 if ($debug) { 00902 ADOConnection::outp("<p><b>Garbage Collection</b>: $sql</p>"); 00903 } 00904 } 00905 00906 // suggested by Cameron, "GaM3R" <gamr@outworld.cx> 00907 if ($optimize) { 00908 $driver = ADODB_Session::driver(); 00909 00910 if (preg_match('/mysql/i', $driver)) { 00911 $sql = "OPTIMIZE TABLE $table"; 00912 } 00913 if (preg_match('/postgres/i', $driver)) { 00914 $sql = "VACUUM $table"; 00915 } 00916 if (!empty($sql)) { 00917 $conn->Execute($sql); 00918 } 00919 } 00920 00921 00922 return true; 00923 } 00924 } 00925 00926 ADODB_Session::_init(); 00927 if (empty($ADODB_SESSION_READONLY)) 00928 register_shutdown_function('session_write_close'); 00929 00930 // for backwards compatability only 00931 function adodb_sess_open($save_path, $session_name, $persist = true) { 00932 return ADODB_Session::open($save_path, $session_name, $persist); 00933 } 00934 00935 // for backwards compatability only 00936 function adodb_sess_gc($t) 00937 { 00938 return ADODB_Session::gc($t); 00939 } 00940 00941 ?>