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