28 if (!defined(
'_ADODB_LAYER')) {
29 require realpath(dirname(__FILE__) .
'/../adodb.inc.php');
32 if (defined(
'ADODB_SESSION'))
return 1;
34 define(
'ADODB_SESSION', dirname(__FILE__));
48 $variables = array( );
49 $a = preg_split(
"/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
50 for( $i = 0; $i < count( $a ); $i = $i+2 ) {
51 $variables[$a[$i]] = unserialize( $a[$i+1] );
63 if (!
$conn)
return false;
65 $old_id = session_id();
66 if (function_exists(
'session_regenerate_id')) {
67 session_regenerate_id();
69 session_id(md5(uniqid(rand(),
true)));
70 $ck = session_get_cookie_params();
71 setcookie(session_name(), session_id(),
false, $ck[
'path'], $ck[
'domain'], $ck[
'secure']);
74 $new_id = session_id();
80 if (empty($ck)) $ck = session_get_cookie_params();
81 setcookie(session_name(), session_id(),
false, $ck[
'path'], $ck[
'domain'], $ck[
'secure']);
97 if ($schemaFile===null) $schemaFile =
ADODB_SESSION .
'/session_schema.xml';
100 if (!
$conn)
return 0;
103 $schema->ParseSchema($schemaFile);
104 return $schema->ExecuteSchema();
128 static $_driver =
'mysql';
136 if (isset(
$GLOBALS[
'ADODB_SESSION_DRIVER'])) {
137 return $GLOBALS[
'ADODB_SESSION_DRIVER'];
147 static $_host =
'localhost';
150 if (!is_null(
$host)) {
151 $_host = trim(
$host);
155 if (isset(
$GLOBALS[
'ADODB_SESSION_CONNECT'])) {
156 return $GLOBALS[
'ADODB_SESSION_CONNECT'];
166 static $_user =
'root';
169 if (!is_null($user)) {
170 $_user = trim($user);
174 if (isset(
$GLOBALS[
'ADODB_SESSION_USER'])) {
175 return $GLOBALS[
'ADODB_SESSION_USER'];
185 static $_password =
'';
188 if (!is_null($password)) {
189 $_password = $password;
193 if (isset(
$GLOBALS[
'ADODB_SESSION_PWD'])) {
194 return $GLOBALS[
'ADODB_SESSION_PWD'];
204 static $_database =
'xphplens_2';
212 if (isset(
$GLOBALS[
'ADODB_SESSION_DB'])) {
213 return $GLOBALS[
'ADODB_SESSION_DB'];
224 static $_persist =
true;
226 if (!is_null($persist)) {
227 $_persist = trim($persist);
239 if (!is_null($lifetime)) {
240 $_lifetime = (int) $lifetime;
244 if (isset(
$GLOBALS[
'ADODB_SESS_LIFE'])) {
249 $_lifetime = ini_get(
'session.gc_maxlifetime');
250 if ($_lifetime <= 1) {
263 static $_debug =
false;
266 if (!is_null($debug)) {
267 $_debug = (bool) $debug;
271 $conn->debug = $_debug;
276 if (isset(
$GLOBALS[
'ADODB_SESS_DEBUG'])) {
277 return $GLOBALS[
'ADODB_SESS_DEBUG'];
287 static $_expire_notify;
290 if (!is_null($expire_notify)) {
291 $_expire_notify = $expire_notify;
295 if (isset(
$GLOBALS[
'ADODB_SESSION_EXPIRE_NOTIFY'])) {
296 return $GLOBALS[
'ADODB_SESSION_EXPIRE_NOTIFY'];
300 return $_expire_notify;
306 static $_table =
'sessions';
309 if (!is_null($table)) {
310 $_table = trim($table);
314 if (isset(
$GLOBALS[
'ADODB_SESSION_TBL'])) {
315 return $GLOBALS[
'ADODB_SESSION_TBL'];
325 static $_optimize =
false;
328 if (!is_null($optimize)) {
329 $_optimize = (bool) $optimize;
333 if (defined(
'ADODB_SESSION_OPTIMIZE')) {
344 static $_sync_seconds = 60;
347 if (!is_null($sync_seconds)) {
348 $_sync_seconds = (int) $sync_seconds;
352 if (defined(
'ADODB_SESSION_SYNCH_SECS')) {
353 return ADODB_SESSION_SYNCH_SECS;
357 return $_sync_seconds;
363 static $_clob =
false;
366 if (!is_null($clob)) {
367 $_clob = strtolower(trim($clob));
371 if (isset(
$GLOBALS[
'ADODB_SESSION_USE_LOBS'])) {
372 return $GLOBALS[
'ADODB_SESSION_USE_LOBS'];
382 static $_data_field_name =
'data';
384 if (!is_null($data_field_name)) {
385 $_data_field_name = trim($data_field_name);
388 return $_data_field_name;
394 static $_filter = array();
396 if (!is_null($filter)) {
397 if (!is_array($filter)) {
398 $filter = array($filter);
409 static $_encryption_key =
'CRYPTED ADODB SESSIONS ROCK!';
411 if (!is_null($encryption_key)) {
412 $_encryption_key = $encryption_key;
415 return $_encryption_key;
431 static $_crc =
false;
433 if (!is_null($crc)) {
443 session_module_name(
'user');
444 session_set_save_handler(
445 array(
'ADODB_Session',
'open'),
446 array(
'ADODB_Session',
'close'),
447 array(
'ADODB_Session',
'read'),
448 array(
'ADODB_Session',
'write'),
449 array(
'ADODB_Session',
'destroy'),
450 array(
'ADODB_Session',
'gc')
478 echo
"<br />\$rs is null or false<br />\n";
484 if (!is_object(
$rs)) {
504 if (
$driver ==
'oci8' ||
$driver ==
'oci8po') $options[
'lob'] =
'CLOB';
516 function open($save_path, $session_name, $persist = null)
531 if (!is_null($persist)) {
537 # these can all be defaulted to in php.ini 538 # assert('$database'); 562 ADOConnection::outp(
'<p>Session: connection failed</p>',
false);
596 $qkey =
$conn->quote($key);
597 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
599 $sql =
"SELECT $data FROM $table WHERE sesskey = $binary $qkey AND expiry >= " . time();
603 #if (ADODB_Session::Lock()) 604 # $rs = $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), $data); 613 $v = reset(
$rs->fields);
614 $filter = array_reverse($filter);
615 foreach ($filter as $f) {
620 $v = rawurldecode($v);
639 global $ADODB_SESSION_READONLY;
641 if (!empty($ADODB_SESSION_READONLY))
return;
657 $qkey =
$conn->qstr($key);
661 $expiry = time() + $lifetime;
663 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
667 if ($crc !==
false && $crc == (strlen($val) . crc32($val))) {
669 ADOConnection::outp(
'<p>Session: Only updating date - crc32 not changed</p>');
673 if ($expire_notify) {
674 $var = reset($expire_notify);
682 $sql =
"UPDATE $table SET expiry = ".$conn->Param(
'0').
",expireref=".
$conn->Param(
'1').
" WHERE $binary sesskey = ".
$conn->Param(
'2').
" AND expiry >= ".
$conn->Param(
'3');
683 $rs =
$conn->Execute(
$sql,array($expiry,$expirevar,$key,time()));
686 $val = rawurlencode($val);
687 foreach ($filter as $f) {
693 $arr = array(
'sesskey' => $key,
'expiry' => $expiry, $data => $val,
'expireref' =>
'');
694 if ($expire_notify) {
695 $var = reset($expire_notify);
698 $arr[
'expireref'] = $$var;
704 $rs =
$conn->Replace($table, $arr,
'sesskey', $autoQuote =
true);
714 $lob_value = sprintf(
'empty_%s()', strtolower($clob));
724 $expiryref =
$conn->qstr($arr[
'expireref']);
726 $rs =
$conn->Execute(
"SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = $qkey");
727 if (
$rs && reset(
$rs->fields) > 0) {
728 $sql =
"UPDATE $table SET expiry = $expiry, $data = $lob_value, expireref=$expiryref WHERE sesskey = $qkey";
730 $sql =
"INSERT INTO $table (expiry, $data, sesskey,expireref) VALUES ($expiry, $lob_value, $qkey,$expiryref)";
737 if (!$rs1) $err =
$conn->ErrorMsg().
"\n";
739 $rs2 =
$conn->UpdateBlob($table, $data, $val,
" sesskey=$qkey", strtoupper($clob));
740 if (!$rs2) $err .=
$conn->ErrorMsg().
"\n";
742 $rs = (
$rs && $rs2) ?
true :
false;
743 $conn->CompleteTrans();
747 ADOConnection::outp(
'<p>Session Replace: ' .
$conn->ErrorMsg() .
'</p>',
false);
752 if (
$conn->databaseType ==
'access') {
753 $sql =
"SELECT sesskey FROM $table WHERE $binary sesskey = $qkey";
764 return $rs ? true :
false;
780 $qkey =
$conn->quote($key);
781 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
783 if ($expire_notify) {
784 reset($expire_notify);
785 $fn = next($expire_notify);
786 $savem =
$conn->SetFetchMode(ADODB_FETCH_NUM);
787 $sql =
"SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey";
790 $conn->SetFetchMode($savem);
795 $ref =
$rs->fields[0];
796 $key =
$rs->fields[1];
804 $sql =
"DELETE FROM $table WHERE $binary sesskey = $qkey";
808 return $rs ? true :
false;
813 function gc($maxlifetime)
828 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
830 if ($expire_notify) {
831 reset($expire_notify);
832 $fn = next($expire_notify);
833 $savem =
$conn->SetFetchMode(ADODB_FETCH_NUM);
834 $sql =
"SELECT expireref, sesskey FROM $table WHERE expiry < $time";
837 $conn->SetFetchMode($savem);
842 $ref =
$rs->fields[0];
843 $key =
$rs->fields[1];
845 $del =
$conn->Execute(
"DELETE FROM $table WHERE sesskey=".
$conn->Param(
'0'),array($key));
850 $conn->CompleteTrans();
855 $sql =
"SELECT sesskey FROM $table WHERE expiry < $time";
857 foreach ($arr as $row) {
858 $sql2 =
"DELETE FROM $table WHERE sesskey=".$conn->Param(
'0');
859 $conn->Execute($sql2,array(reset($row)));
862 $sql =
"DELETE FROM $table WHERE expiry < $time";
868 ADOConnection::outp(
"<p><b>Garbage Collection</b>: $sql</p>");
876 if (preg_match(
'/mysql/i',
$driver)) {
877 $sql =
"OPTIMIZE TABLE $table";
879 if (preg_match(
'/postgres/i',
$driver)) {
880 $sql =
"VACUUM $table";
889 if (
$conn->dataProvider ===
'oci8') {
890 $sql .=
"TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')";
894 $sql .=
" FROM $table";
898 $dbts = reset(
$rs->fields);
900 $dbt =
$conn->UnixTimeStamp($dbts);
903 if (abs($dbt - $t) >= $sync_seconds) {
905 ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " .
906 " database=$dbt ($dbts), webserver=$t (diff=". (abs($dbt - $t) / 60) .
' minutes)';
909 ADOConnection::outp(
"<p>$msg</p>");
920 if (empty($ADODB_SESSION_READONLY))
921 register_shutdown_function(
'session_write_close');
adodb_unserialize( $serialized_string)
adodb_session_create_table($schemaFile=null, $conn=null)
dataFieldName($data_field_name=null)
encryptionKey($encryption_key=null)
adodb_sess_open($save_path, $session_name, $persist=true)
adodb_session_regenerate_id()
if(isset($_REQUEST['nrows'])) else $rs
config($driver, $host, $user, $password, $database=false, $options=false)
rs2html(&$rs, $ztabhtml=false, $zheaderarray=false, $htmlspecialchars=true, $echo=true)
open($save_path, $session_name, $persist=null)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
expireNotify($expire_notify=null)
syncSeconds($sync_seconds=null)