58 if (!defined(
'_ADODB_LAYER')) {
59 require realpath(dirname(__FILE__) .
'/../adodb.inc.php');
62 if (defined(
'ADODB_SESSION'))
return 1;
64 define(
'ADODB_SESSION', dirname(__FILE__));
78 $variables = array( );
79 $a = preg_split(
"/(\w+)\|/", $serialized_string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
80 for( $i = 0; $i < count( $a ); $i = $i+2 ) {
81 $variables[$a[$i]] = unserialize( $a[$i+1] );
93 if (!
$conn)
return false;
95 $old_id = session_id();
96 if (function_exists(
'session_regenerate_id')) {
97 session_regenerate_id();
99 session_id(md5(uniqid(rand(),
true)));
100 $ck = session_get_cookie_params();
101 setcookie(session_name(), session_id(),
false, $ck[
'path'], $ck[
'domain'], $ck[
'secure']);
104 $new_id = session_id();
110 if (empty($ck)) $ck = session_get_cookie_params();
111 setcookie(session_name(), session_id(),
false, $ck[
'path'], $ck[
'domain'], $ck[
'secure']);
127 if ($schemaFile===null) $schemaFile =
ADODB_SESSION .
'/session_schema2.xml';
130 if (!
$conn)
return 0;
133 $schema->ParseSchema($schemaFile);
134 return $schema->ExecuteSchema();
159 static $_driver =
'mysql';
167 if (isset(
$GLOBALS[
'ADODB_SESSION_DRIVER'])) {
168 return $GLOBALS[
'ADODB_SESSION_DRIVER'];
178 static $_host =
'localhost';
181 if (!is_null(
$host)) {
182 $_host = trim(
$host);
186 if (isset(
$GLOBALS[
'ADODB_SESSION_CONNECT'])) {
187 return $GLOBALS[
'ADODB_SESSION_CONNECT'];
196 static function user($user = null)
198 static $_user =
'root';
201 if (!is_null($user)) {
202 $_user = trim($user);
206 if (isset(
$GLOBALS[
'ADODB_SESSION_USER'])) {
207 return $GLOBALS[
'ADODB_SESSION_USER'];
218 static $_password =
'';
221 if (!is_null($password)) {
222 $_password = $password;
226 if (isset(
$GLOBALS[
'ADODB_SESSION_PWD'])) {
227 return $GLOBALS[
'ADODB_SESSION_PWD'];
238 static $_database =
'';
246 if (isset(
$GLOBALS[
'ADODB_SESSION_DB'])) {
247 return $GLOBALS[
'ADODB_SESSION_DB'];
257 static $_persist =
true;
259 if (!is_null($persist)) {
260 $_persist = trim($persist);
273 if (!is_null($lifetime)) {
274 $_lifetime = (int) $lifetime;
278 if (isset(
$GLOBALS[
'ADODB_SESS_LIFE'])) {
283 $_lifetime = ini_get(
'session.gc_maxlifetime');
284 if ($_lifetime <= 1) {
296 static function debug($debug = null)
298 static $_debug =
false;
301 if (!is_null($debug)) {
302 $_debug = (bool) $debug;
306 #$conn->debug = $_debug; 311 if (isset(
$GLOBALS[
'ADODB_SESS_DEBUG'])) {
312 return $GLOBALS[
'ADODB_SESS_DEBUG'];
323 static $_expire_notify;
326 if (!is_null($expire_notify)) {
327 $_expire_notify = $expire_notify;
331 if (isset(
$GLOBALS[
'ADODB_SESSION_EXPIRE_NOTIFY'])) {
332 return $GLOBALS[
'ADODB_SESSION_EXPIRE_NOTIFY'];
336 return $_expire_notify;
341 static function table($table = null)
343 static $_table =
'sessions2';
346 if (!is_null($table)) {
347 $_table = trim($table);
351 if (isset(
$GLOBALS[
'ADODB_SESSION_TBL'])) {
352 return $GLOBALS[
'ADODB_SESSION_TBL'];
363 static $_optimize =
false;
366 if (!is_null($optimize)) {
367 $_optimize = (bool) $optimize;
371 if (defined(
'ADODB_SESSION_OPTIMIZE')) {
389 static function clob($clob = null) {
390 static $_clob =
false;
393 if (!is_null($clob)) {
394 $_clob = strtolower(trim($clob));
398 if (isset(
$GLOBALS[
'ADODB_SESSION_USE_LOBS'])) {
399 return $GLOBALS[
'ADODB_SESSION_USE_LOBS'];
416 static $_filter = array();
418 if (!is_null($filter)) {
419 if (!is_array($filter)) {
420 $filter = array($filter);
431 static $_encryption_key =
'CRYPTED ADODB SESSIONS ROCK!';
433 if (!is_null($encryption_key)) {
434 $_encryption_key = $encryption_key;
437 return $_encryption_key;
447 return isset(
$GLOBALS[
'ADODB_SESS_CONN']) ?
$GLOBALS[
'ADODB_SESS_CONN'] :
false;
452 static function _crc($crc = null) {
453 static $_crc =
false;
455 if (!is_null($crc)) {
465 session_module_name(
'user');
466 session_set_save_handler(
467 array(
'ADODB_Session',
'open'),
468 array(
'ADODB_Session',
'close'),
469 array(
'ADODB_Session',
'read'),
470 array(
'ADODB_Session',
'write'),
471 array(
'ADODB_Session',
'destroy'),
472 array(
'ADODB_Session',
'gc')
500 echo
"<br />\$rs is null or false<br />\n";
506 if (!is_object(
$rs)) {
528 if (strncmp(
$driver,
'oci8', 4) == 0) $options[
'lob'] =
'CLOB';
540 static function open($save_path, $session_name, $persist = null)
555 if (!is_null($persist)) {
561 # these can all be defaulted to in php.ini 562 # assert('$database'); 570 ADOConnection::outp(
" driver=$driver user=$user db=$database ");
573 if (empty(
$conn->_connectionID)) {
588 ADOConnection::outp(
'<p>Session: connection failed</p>',
false);
621 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
623 global $ADODB_SESSION_SELECT_FIELDS;
624 if (!isset($ADODB_SESSION_SELECT_FIELDS)) $ADODB_SESSION_SELECT_FIELDS =
'sessdata';
625 $sql =
"SELECT $ADODB_SESSION_SELECT_FIELDS FROM $table WHERE sesskey = $binary ".$conn->Param(0).
" AND expiry >= " .
$conn->sysTimeStamp;
630 #if (ADODB_Session::Lock()) 631 # $rs = $conn->RowLock($table, "$binary sesskey = $qkey AND expiry >= " . time(), sessdata); 639 $v = reset(
$rs->fields);
640 $filter = array_reverse($filter);
641 foreach ($filter as $f) {
646 $v = rawurldecode($v);
665 global $ADODB_SESSION_READONLY;
667 if (!empty($ADODB_SESSION_READONLY))
return;
682 if ($debug)
$conn->debug = 1;
683 $sysTimeStamp =
$conn->sysTimeStamp;
687 $expiry =
$conn->OffsetDate($lifetime/(24*3600),$sysTimeStamp);
689 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
693 if ($crc !==
'00' && $crc !==
false && $crc == (strlen($oval) . crc32($oval))) {
695 echo
'<p>Session: Only updating date - crc32 not changed</p>';
699 if ($expire_notify) {
700 $var = reset($expire_notify);
708 $sql =
"UPDATE $table SET expiry = $expiry ,expireref=".$conn->Param(
'0').
", modified = $sysTimeStamp WHERE $binary sesskey = ".
$conn->Param(
'1').
" AND expiry >= $sysTimeStamp";
712 $val = rawurlencode($oval);
713 foreach ($filter as $f) {
720 if ($expire_notify) {
721 $var = reset($expire_notify);
729 $rs =
$conn->Execute(
"SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".
$conn->Param(0),array($key));
732 if (
$rs && reset(
$rs->fields) > 0) {
733 $sql =
"UPDATE $table SET expiry=$expiry, sessdata=".$conn->Param(0).
", expireref= ".
$conn->Param(1).
",modified=$sysTimeStamp WHERE sesskey = ".
$conn->Param(2);
736 $sql =
"INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified) 737 VALUES ($expiry,".$conn->Param(
'0').
", ".
$conn->Param(
'1').
", ".
$conn->Param(
'2').
", $sysTimeStamp, $sysTimeStamp)";
745 if (strncmp(
$driver,
'oci8', 4) == 0) $lob_value = sprintf(
'empty_%s()', strtolower($clob));
746 else $lob_value =
'null';
750 $rs =
$conn->Execute(
"SELECT COUNT(*) AS cnt FROM $table WHERE $binary sesskey = ".
$conn->Param(0),array($key));
752 if (
$rs && reset(
$rs->fields) > 0) {
753 $sql =
"UPDATE $table SET expiry=$expiry, sessdata=$lob_value, expireref= ".$conn->Param(0).
",modified=$sysTimeStamp WHERE sesskey = ".
$conn->Param(
'1');
756 $sql =
"INSERT INTO $table (expiry, sessdata, expireref, sesskey, created, modified) 757 VALUES ($expiry,$lob_value, ".
$conn->Param(
'0').
", ".
$conn->Param(
'1').
", $sysTimeStamp, $sysTimeStamp)";
762 $qkey =
$conn->qstr($key);
763 $rs2 =
$conn->UpdateBlob($table,
'sessdata', $val,
" sesskey=$qkey", strtoupper($clob));
764 if ($debug) echo
"<hr>",htmlspecialchars($oval),
"<hr>";
771 ADOConnection::outp(
'<p>Session Replace: ' .
$conn->ErrorMsg() .
'</p>',
false);
776 if (
$conn->databaseType ==
'access') {
777 $sql =
"SELECT sesskey FROM $table WHERE $binary sesskey = $qkey";
788 return $rs ? true :
false;
802 if ($debug)
$conn->debug = 1;
805 $qkey =
$conn->quote($key);
806 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
808 if ($expire_notify) {
809 reset($expire_notify);
810 $fn = next($expire_notify);
811 $savem =
$conn->SetFetchMode(ADODB_FETCH_NUM);
812 $sql =
"SELECT expireref, sesskey FROM $table WHERE $binary sesskey = $qkey";
815 $conn->SetFetchMode($savem);
820 $ref =
$rs->fields[0];
821 $key =
$rs->fields[1];
829 $sql =
"DELETE FROM $table WHERE $binary sesskey = $qkey";
835 return $rs ? true :
false;
840 static function gc($maxlifetime)
863 $time =
$conn->OffsetDate(-$maxlifetime/24/3600,
$conn->sysTimeStamp);
864 $binary =
$conn->dataProvider ===
'mysql' ?
'/*! BINARY */' :
'';
866 if ($expire_notify) {
867 reset($expire_notify);
868 $fn = next($expire_notify);
873 $savem =
$conn->SetFetchMode(ADODB_FETCH_NUM);
874 $sql =
"SELECT expireref, sesskey FROM $table WHERE expiry < $time ORDER BY 2"; # add order by to prevent deadlock
877 $conn->SetFetchMode($savem);
879 $tr =
$conn->hasTransactions;
880 if ($tr)
$conn->BeginTrans();
884 $ref = $rs->fields[0];
885 $key = $rs->fields[1];
886 if ($fn) $fn($ref, $key);
887 $del =
$conn->Execute(
"DELETE FROM $table WHERE sesskey=".
$conn->Param(
'0'),array($key));
890 if ($tr && $ccnt % $COMMITNUM == 0) {
891 if ($debug) echo
"Commit<br>\n";
892 $conn->CommitTrans();
898 if ($tr)
$conn->CommitTrans();
906 if (preg_match(
'/mysql/i',
$driver)) {
907 $sql =
"OPTIMIZE TABLE $table";
909 if (preg_match(
'/postgres/i',
$driver)) {
910 $sql =
"VACUUM $table";
923 if (empty($ADODB_SESSION_READONLY))
924 register_shutdown_function(
'session_write_close');
static password($password=null)
static config($driver, $host, $user, $password, $database=false, $options=false)
encryptionKey($encryption_key=null)
static syncSeconds($sync_seconds=null)
static optimize($optimize=null)
if(isset($_REQUEST['nrows'])) else $rs
static open($save_path, $session_name, $persist=null)
static write($key, $oval)
static lifetime($lifetime=null)
static dataFieldName($data_field_name=null)
static expireNotify($expire_notify=null)
static table($table=null)
static encryptionKey($encryption_key=null)
static driver($driver=null)
adodb_sess_open($save_path, $session_name, $persist=true)
adodb_unserialize( $serialized_string)
rs2html(&$rs, $ztabhtml=false, $zheaderarray=false, $htmlspecialchars=true, $echo=true)
static debug($debug=null)
open($save_path, $session_name, $persist=null)
static filter($filter=null)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static database($database=null)
adodb_session_create_table($schemaFile=null, $conn=null)
static persist($persist=null)
expireNotify($expire_notify=null)
adodb_session_regenerate_id()