function __construct($conn_options, $persist = TRUE, $debug = FALSE, $sess_table = 'sessao') { $ret = FALSE; list($host, $database, $user, $password, $port) = array_values($conn_options); $host .= ':' . $port; $options['table'] = $sess_table; $this->session_table = $sess_table; ADOdb_Session::config('postgres', $host, $user, $password, $database, $options); ADODB_Session::open(false, false, $connectMode = $persist); if (isset($GLOBALS['ADODB_SESS_CONN']) && is_object($GLOBALS['ADODB_SESS_CONN'])) { ADOdb_session::Persist($connectMode = $persist); $GLOBALS['ADODB_SESS_CONN']->debug = $debug; // limpa outras sessoes expiradas e inativas por mais de 15 minutos (padr�o) $this->clear_expired_sessions(); @session_start(); } }
public static function init() { if (!wbCore::isFuncDisabled('ini_set')) { // PHP configuration variables // Stop adding SID to URLs ini_set('session.use_trans_sid', 0); // User-defined save handler ini_set('session.save_handler', 'user'); // How to store data ini_set('session.serialize_handler', 'php'); // Use cookie to store the session ID ini_set('session.use_cookies', 1); // Name of our cookie ini_set('session.name', 'WEBISID'); $path = wbServer::getBaseURI(); if (empty($path)) { $path = '/'; } // Lifetime of our cookie. Session lasts set number of days $lifetime = wbConfig::get('Session.Duration') * 86400; ini_set('session.cookie_lifetime', $lifetime); // Cookie path // this should be customized for multi-server setups wanting to share // sessions ini_set('session.cookie_path', $path); // Garbage collection ini_set('session.gc_probability', 1); // Inactivity timeout for user sessions ini_set('session.gc_maxlifetime', wbConfig::get('Session.InactivityTimeout') * 60); // Auto-start session ini_set('session.auto_start', 1); } include_once 'lib/adodb/session/adodb-session2.php'; $GLOBALS['ADODB_SESS_CONN'] =& wbDB::getConn(); ADODB_Session::table(wbConfig::get('DB.prefix') . '_sessions'); session_start(); }
function adodb_session_regenerate_id() { $conn = ADODB_Session::_conn(); if (!$conn) { return false; } $old_id = session_id(); if (function_exists('session_regenerate_id')) { session_regenerate_id(); } else { session_id(md5(uniqid(rand(), true))); $ck = session_get_cookie_params(); setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); //@session_start(); } $new_id = session_id(); $ok = $conn->Execute('UPDATE ' . ADODB_Session::table() . ' SET sesskey=' . $conn->qstr($new_id) . ' WHERE sesskey=' . $conn->qstr($old_id)); /* it is possible that the update statement fails due to a collision */ if (!$ok) { session_id($old_id); if (empty($ck)) { $ck = session_get_cookie_params(); } setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']); return false; } return true; }
function LogoutNotification($SessionID) { global $CFG, $SESSION, $DB; // Delete session of user using $SessionID if (empty($CFG->dbsessions)) { // File session $dir = $CFG->dataroot . '/sessions'; if (is_dir($dir)) { if ($dh = opendir($dir)) { // Read all session files while (($file = readdir($dh)) !== false) { // Check if it is a file if (is_file($dir . '/' . $file)) { $session_key = preg_replace('/sess_/', '', $file); // Read session file data $data = file($dir . '/' . $file); if (isset($data[0])) { $user_session = unserializesession($data[0]); // Check if we have found session that shall be deleted if (isset($user_session['SESSION']) && isset($user_session['SESSION']->shibboleth_session_id)) { // If there is a match, delete file if ($user_session['SESSION']->shibboleth_session_id == $SessionID) { // Delete session file if (!unlink($dir . '/' . $file)) { return new SoapFault('LogoutError', 'Could not delete Moodle session file.'); } } } } } } closedir($dh); } } } else { // DB Session //TODO: this needs to be rewritten to use new session stuff if (!empty($CFG->sessiontimeout)) { $ADODB_SESS_LIFE = $CFG->sessiontimeout; } if ($user_session_data = $DB->get_records_sql('SELECT sesskey, sessdata FROM {sessions2} WHERE expiry > NOW()')) { foreach ($user_session_data as $session_data) { // Get user session $user_session = adodb_unserialize(urldecode($session_data->sessdata)); if (isset($user_session['SESSION']) && isset($user_session['SESSION']->shibboleth_session_id)) { // If there is a match, delete file if ($user_session['SESSION']->shibboleth_session_id == $SessionID) { // Delete this session entry if (ADODB_Session::destroy($session_data->sesskey) !== true) { return new SoapFault('LogoutError', 'Could not delete Moodle session entry in database.'); } } } } } } // If now SoapFault was thrown the function will return OK as the SP assumes }
* * @author Organisation: Queen's University * @author Unit: School of Medicine * @author Developer: Matt Simpson <*****@*****.**> * @copyright Copyright 2010 Queen's University. All Rights Reserved. * */ $ADODB_QUOTE_FIELDNAMES = true; // Whether or not you want ADOdb to backtick field names in AutoExecute, GetInsertSQL and GetUpdateSQL. define("ADODB_QUOTE_FIELDNAMES", $ADODB_QUOTE_FIELDNAMES); // Information required to start a new database connection. $db = NewADOConnection(DATABASE_TYPE); $db->Connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME); $db->SetFetchMode(ADODB_FETCH_ASSOC); if (defined("DEFAULT_CHARSET") && isset($ENTRADA_CHARSETS) && is_array($ENTRADA_CHARSETS) && array_key_exists(DEFAULT_CHARSET, $ENTRADA_CHARSETS)) { $db->Execute("SET NAMES " . $db->qstr($ENTRADA_CHARSETS[DEFAULT_CHARSET]["mysql_names"]) . " COLLATE " . $db->qstr($ENTRADA_CHARSETS[DEFAULT_CHARSET]["mysql_collate"])); } $db->debug = isset($DEVELOPER_IPS) && is_array($DEVELOPER_IPS) && isset($_SERVER["REMOTE_ADDR"]) && in_array($_SERVER["REMOTE_ADDR"], $DEVELOPER_IPS) && isset($_GET["debug"]) ? true : false; @ini_set("session.name", SESSION_NAME); @ini_set("session.gc_maxlifetime", SESSION_EXPIRES); if (defined("ADODB_SESSION") && defined("DATABASE_SESSIONS") && DATABASE_SESSIONS) { require_once "Entrada/adodb/session/adodb-session2.php"; ADODB_Session::config(SESSION_DATABASE_TYPE, SESSION_DATABASE_HOST, SESSION_DATABASE_USER, SESSION_DATABASE_PASS, SESSION_DATABASE_NAME, array("table" => "sessions")); ADODB_Session::encryptionKey(ENCRYPTION_KEY); ADODB_Session::open(false, false, false); ADODB_Session::optimize(true); ADODB_Session::expireNotify(array("PROXY_ID", "expired_session")); session_start(); } else { session_start(); }
function _sessionKey() { return crypt(ADODB_Session::encryptionKey(), session_id()); }
<?php /* V4.90 8 June 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. Contributed by Ross Smith (adodb@netebb.com). Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. Set tabs to 4 for best viewing. */ /* This file is provided for backwards compatibility purposes */ require_once dirname(__FILE__) . '/adodb-session.php'; ADODB_Session::clob('CLOB');
static function gc($maxlifetime) { $conn = ADODB_Session::_conn(); $debug = ADODB_Session::debug(); $expire_notify = ADODB_Session::expireNotify(); $optimize = ADODB_Session::optimize(); $table = ADODB_Session::table(); if (!$conn) { return false; } $debug = ADODB_Session::debug(); if ($debug) { $conn->debug = 1; $COMMITNUM = 2; } else { $COMMITNUM = 20; } //assert('$table'); $time = $conn->OffsetDate(-$maxlifetime / 24 / 3600, $conn->sysTimeStamp); $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; if ($expire_notify) { reset($expire_notify); $fn = next($expire_notify); } else { $fn = false; } $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time} ORDER BY 2"; # add order by to prevent deadlock $rs = $conn->SelectLimit($sql, 1000); if ($debug) { ADODB_Session::_dumprs($rs); } $conn->SetFetchMode($savem); if ($rs) { $tr = $conn->hasTransactions; if ($tr) { $conn->BeginTrans(); } $keys = array(); $ccnt = 0; while (!$rs->EOF) { $ref = $rs->fields[0]; $key = $rs->fields[1]; if ($fn) { $fn($ref, $key); } $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key)); $rs->MoveNext(); $ccnt += 1; if ($tr && $ccnt % $COMMITNUM == 0) { if ($debug) { echo "Commit<br>\n"; } $conn->CommitTrans(); $conn->BeginTrans(); } } $rs->Close(); if ($tr) { $conn->CommitTrans(); } } // suggested by Cameron, "GaM3R" <*****@*****.**> if ($optimize) { $driver = ADODB_Session::driver(); if (preg_match('/mysql/i', $driver)) { $sql = "OPTIMIZE TABLE {$table}"; } if (preg_match('/postgres/i', $driver)) { $sql = "VACUUM {$table}"; } if (!empty($sql)) { $conn->Execute($sql); } } return true; }
</table></td> <?php $heading = array(); $contents = array(); if (isset($info)) { $heading[] = array('text' => '<b>' . TABLE_HEADING_SHOPPING_CART . '</b><br />'); if (STORE_SESSIONS == '1') { $sessionstable = $oostable['sessions']; $session_data = $dbconn->Execute("SELECT data FROM $sessionstable WHERE sesskey = '" . $info . "'"); if (STORE_SESSIONS_CRYPT == '1') { include_once '../includes/lib/adodb/session/crypt.inc.php'; $Crypt = new MD5Crypt; $session_data = rawurldecode($Crypt->Decrypt(reset($session_data->fields), crypt(ADODB_Session::encryptionKey(), $info))); } else { $session_data = rawurldecode($session_data->fields['data']); } } else { if ( (file_exists(oos_session_save_path() . '/sess_' . $info)) && (filesize(oos_session_save_path() . '/sess_' . $info) > 0) ) { $session_data = file(oos_session_save_path() . '/sess_' . $info); $session_data = trim(implode('', $session_data)); } } $currency = unserialize(oos_get_serialized_variable($session_data, 'currency', 'string')); $cart = unserialize(oos_get_serialized_variable($session_data, 'cart', 'object')); if (isset($cart) && is_object($cart)) {
error_reporting(E_ALL ^ E_NOTICE); date_default_timezone_set('Europe/Kiev'); require_once _ROOT . 'vendor/autoload.php'; include_once _ROOT . "vendor/adodb/adodb-php/adodb-exceptions.inc.php"; //чтение конфигурации $_config = parse_ini_file(_ROOT . 'config/config.ini', true); // phpQuery::$debug = true; // Подключение фреймворка require_once _ZIPPY . 'zippy.inc.php'; //Параметры соединения с БД \ZCL\DB\DB::config($_config['db']['host'], $_config['db']['name'], $_config['db']['user'], $_config['db']['pass']); //Настройка сессии в БД if ($_config["common"]["sessiondb"] == "1") { include_once _ROOT . "vendor/adodb/adodb-php/session/adodb-session2.php"; \ADODB_Session::config('mysqli', $_config['db']['host'], $_config['db']['user'], $_config['db']['pass'], $_config['db']['name'], array('table' => 'system_session')); \ADODB_Session::Persist($connectMode = false); } //подключение ядра системмы require_once _ROOT . 'system/start.inc.php'; require_once _ROOT . 'erp/start.inc.php'; //загружаем модули $modules = array(); /* $modulespath = _ROOT . 'modules/'; if ($handle = @opendir($modulespath)) { while (false !== ($file = readdir($handle))) { if (is_dir($modulespath . $file) && strlen($file) > 2) { $startfile = $modulespath . $file . '/start.inc.php'; if(file_exists($startfile)){ $modules[] = $file; require_once $startfile;
calc("Last Moderated Image", $sql); $table[] = array("Parameter" => '', "Value" => ''); $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Images Submitted in last 24 hours", $sql, 600); $sql = "SELECT COUNT(DISTINCT user_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Image Contributors in last 24 hours", $sql, 3600); $sql = "SELECT COUNT(DISTINCT moderator_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 48 HOUR) and moderator_id > 0 and moderated > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Active Moderators in last 24 hours", $sql, 3600); $table[] = array("Parameter" => '', "Value" => ''); $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 7 DAY)"; calc("Images Submitted in last 7 days", $sql, 3600 * 3); $sql = "SELECT COUNT(DISTINCT user_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 7 DAY)"; calc("Image Contributors in last 7 days", $sql, 3600 * 3); $table[] = array("Parameter" => '', "Value" => ''); $sql = "SELECT COUNT(DISTINCT ipaddr) FROM sessions WHERE EXPIRY > UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL 24 MINUTE))"; $db2 = ADODB_Session::_conn(); $table[] = array("Parameter" => "Approx Visitors in last 24 <u>minutes</u>", "Value" => $db2->getOne($sql)); $sql = "SELECT COUNT(DISTINCT user_id)-1 FROM autologin WHERE created > DATE_SUB(NOW(), INTERVAL 1 HOUR)"; calc("Approx Regular Users visited in last hour", $sql); $table[] = array("Parameter" => '', "Value" => ''); $sql = "SELECT COUNT(*) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 1 HOUR)"; calc("Forum Posts in last hour", $sql); $sql = "SELECT COUNT(DISTINCT poster_id) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 1 HOUR)"; calc("Forum Posters in last hour", $sql); $table[] = array("Parameter" => '', "Value" => ''); $sql = "SELECT COUNT(*) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Forum Posts in last 24 hours", $sql); $sql = "SELECT COUNT(DISTINCT poster_id) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Forum Posters in last 24 hours", $sql); $sql = "SELECT COUNT(DISTINCT user_id) FROM geobb_lastviewed WHERE ts > DATE_SUB(NOW() , INTERVAL 24 HOUR)"; calc("Forum Viewers in last 24 hours", $sql);
function NotifyExpire($ref, $key) { print "<p><b>Notify Expiring={$ref}, sessionkey={$key}</b></p>"; } $ADODB_SESSION_DRIVER = 'mysql'; $ADODB_SESSION_CONNECT = 'localhost'; $ADODB_SESSION_USER = '******'; $ADODB_SESSION_PWD = ''; $ADODB_SESSION_DB = 'pos'; $ADODB_SESS_LIFE = 120; //$ADODB_SESS_DEBUG = true; $USER = '******'; $ADODB_SESSION_EXPIRE_NOTIFY = array('USER', 'NotifyExpire'); error_reporting(E_ALL); include 'session/adodb-cryptsession.php'; session_start(); print "session id <br>"; print session_id() . "<br>"; if (ADODB_Session::read(session_id()) == '') { ADODB_Session::destroy(session_id()); //ADODB_Session::gc(160); //unset($_COOKIE['PHPSESSID']); //unset($_SESSION); //session_destroy(); //session_unset(); print "session info is empty <br>"; } print ADODB_Session::read(session_id()) . "<br>"; print date("F j, Y, g:i a s", 1095289294) . "<br>"; print date("F j, Y, g:i a s", 1095289337); ob_end_flush();
// No errors ini_set('display_errors', '0'); // Don't show them $db_logging = false; // True gives an admin log entry for any SQL calls that update/insert/delete, and turns on adodb's sql logging. Only for use during development!This makes a huge amount of logs! You have been warned!! } ini_set('url_rewriter.tags', ''); // Ensure that the session id is *not* passed on the url - this is a possible security hole for logins - including admin. global $ADODB_CRYPT_KEY; global $ADODB_SESSION_CONNECT, $ADODB_SESSION_USER, $ADODB_SESSION_DB; $ADODB_SESS_CONN = ''; $ADODB_SESSION_TBL = $db_prefix . "sessions"; // We explicitly use encrypted sessions, but this adds compression as well. ADODB_Session::encryptionKey($ADODB_CRYPT_KEY); // The data field name "data" violates SQL reserved words - switch it to SESSDATA ADODB_Session::dataFieldName('SESSDATA'); global $db; connectdb(); $db->prefix = $db_prefix; $db->logging = $db_logging; if ($db_logging) { adodb_perf::table("{$db->prefix}adodb_logsql"); $db->LogSQL(); // Turn on adodb performance logging } if (!isset($index_page)) { $index_page = false; } if (!$index_page) { // Ensure that we do not set cookies on the index page, until the player chooses to allow them. if (!isset($_SESSION)) {
} // is session data stored in DB or in filesystem? if ($gBitSystem->isFeatureActive('site_store_session_db') && !empty($gBitDbType)) { if (file_exists(EXTERNAL_LIBS_PATH . 'adodb/session/adodb-session.php')) { include_once EXTERNAL_LIBS_PATH . 'adodb/session/adodb-session.php'; } elseif (file_exists(UTIL_PKG_PATH . 'adodb/session/adodb-session.php')) { include_once UTIL_PKG_PATH . 'adodb/session/adodb-session.php'; } if (class_exists('ADODB_Session')) { ADODB_Session::dataFieldName('session_data'); ADODB_Session::driver($gBitDbType); ADODB_Session::host($gBitDbHost); ADODB_Session::user($gBitDbUser); ADODB_Session::password($gBitDbPassword); ADODB_Session::database($gBitDbName); ADODB_Session::table(BIT_DB_PREFIX . 'sessions'); ini_set('session.save_handler', 'user'); } } session_name(BIT_SESSION_NAME); if ($gBitSystem->isFeatureActive('users_remember_me')) { session_set_cookie_params($gBitSystem->getConfig('site_session_lifetime'), $gBitSystem->getConfig('cookie_path', BIT_ROOT_URL), $gBitSystem->getConfig('cookie_domain', '')); } else { session_set_cookie_params($gBitSystem->getConfig('site_session_lifetime'), BIT_ROOT_URL, ''); } // just use a simple COOKIE (unique random string) that is linked to the users_cnxn table. // This way, nuking rows in the users_cnxn table can log people out and is much more reliable than SESSIONS global $gShellScript; if (empty($gShellScript)) { if (session_status() == PHP_SESSION_NONE) { session_start();
// Since we now have the config values(including perf_logging), if the admin wants perf logging on - turn it on. if (isset($perf_logging) && $perf_logging) { $debug_query = $db->SelectLimit("SELECT * from {$db_prefix}adodb_logsql", 1); if ($debug_query) { adodb_perf::table("{$db_prefix}adodb_logsql"); $db->LogSQL(); } } } // Ensure that the sessions table has been created, and if so, start a session. // I bet there is a more elegant way to do this, but this works for all my testing scenarios, so its in for now. $debug_query = $db->Execute("SHOW TABLES LIKE '{$db_prefix}sessions'"); db_op_result($debug_query, __LINE__, __FILE__); $row = $debug_query->fields; if ($debug_query) { // We explicitly use encrypted sessions, but this adds compression as well. $ADODB_SESSION_TBL = $db_prefix . "sessions"; ADODB_Session::filter(new ADODB_Compress_Gzip()); // The data field name "data" violates SQL reserved words - switch it to session_data. ADODB_Session::dataFieldName('session_data'); session_start(); } } $smarty = new Smarty(); if (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); // Get Proxy IP address for user } else { $ip = getenv("REMOTE_ADDR"); // Get IP address for user }
function gc($maxlifetime) { $conn =& ADODB_Session::_conn(); $debug = ADODB_Session::debug(); $expire_notify = ADODB_Session::expireNotify(); $optimize = ADODB_Session::optimize(); $table = ADODB_Session::table(); if (!$conn) { return false; } //assert('$table'); $time = $conn->sysTimeStamp; $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; if ($expire_notify) { reset($expire_notify); $fn = next($expire_notify); $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time}"; $rs =& $conn->Execute($sql); ADODB_Session::_dumprs($rs); $conn->SetFetchMode($savem); if ($rs) { $conn->StartTrans(); $keys = array(); while (!$rs->EOF) { $ref = $rs->fields[0]; $key = $rs->fields[1]; $fn($ref, $key); $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key)); $rs->MoveNext(); } $rs->Close(); $conn->CompleteTrans(); } } else { if (0) { $sql = "SELECT sesskey FROM {$table} WHERE expiry < {$time}"; $arr =& $conn->GetAll($sql); foreach ($arr as $row) { $sql2 = "DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'); $conn->Execute($sql2, array(reset($row))); } } else { $sql = "DELETE FROM {$table} WHERE expiry < {$time}"; $rs =& $conn->Execute($sql); ADODB_Session::_dumprs($rs); if ($rs) { $rs->Close(); } } if ($debug) { ADOConnection::outp("<p><b>Garbage Collection</b>: {$sql}</p>"); } } // suggested by Cameron, "GaM3R" <*****@*****.**> if ($optimize) { $driver = ADODB_Session::driver(); if (preg_match('/mysql/i', $driver)) { $sql = "OPTIMIZE TABLE {$table}"; } if (preg_match('/postgres/i', $driver)) { $sql = "VACUUM {$table}"; } if (!empty($sql)) { $conn->Execute($sql); } } return true; }
} else { $_SESSION['MONKEY'][0] += 1; } if (!isset($_GET['nochange'])) { @($_SESSION['AVAR'] += 1); } ### START DISPLAY print "<h3>PHP " . PHP_VERSION . "</h3>"; print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>"; print "<hr /> <b>Cookies</b>: "; print_r($_COOKIE); var_dump($_SESSION['MONKEY']); ### RANDOMLY PERFORM Garbage Collection ### In real-production environment, this is done for you ### by php's session extension, which calls adodb_sess_gc() ### automatically for you. See php.ini's ### session.cookie_lifetime and session.gc_probability if (rand() % 5 == 0) { print "<hr /><p><b>Garbage Collection</b></p>"; adodb_sess_gc(10); if (rand() % 2 == 0) { print "<p>Random own session destroy</p>"; session_destroy(); } } else { $DB = ADODB_Session::_conn(); $sessk = $DB->qstr('%AZ' . rand() . time()); $olddate = $DB->DBTimeStamp(time() - 30 * 24 * 3600); $rr = $DB->qstr(rand()); $DB->Execute("insert into {$options['table']} (sesskey,expiry,expireref,sessdata,created,modified) values ({$sessk},{$olddate}, {$rr},'',{$olddate},{$olddate})"); }
ADODB_Session::host($host); ADODB_Session::lifetime($lifetime); ADODB_Session::optimize($optimize); ADODB_Session::password($password); ADODB_Session::syncSeconds($sync_seconds); ADODB_Session::table($table); ADODB_Session::user($user); } function NotifyFn($var, $sesskey) { echo "NotifyFn({$var}, {$sesskey}) called<br />\n"; } if ($expire_notify) { $ADODB_SESSION_EXPIRE_NOTIFY = array('debug', 'NotifyFn'); if (class_exists('ADODB_Session')) { ADODB_Session::expireNotify(array('debug', 'NotifyFn')); } } session_start(); $register = true; if (!empty($_REQUEST['submit'])) { switch ($_REQUEST['submit']) { case 'Change Driver': case 'Delete Session': $_SESSION = array(); setcookie(session_name(), '', time() - 2592000, '/', '', 0); session_destroy(); $register = false; break; default: }
function gc($maxlifetime) { $conn =& ADODB_Session::_conn(); $debug = ADODB_Session::debug(); $expire_notify = ADODB_Session::expireNotify(); $optimize = ADODB_Session::optimize(); $sync_seconds = ADODB_Session::syncSeconds(); $table = ADODB_Session::table(); if (!$conn) { return false; } $time = time(); $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : ''; if ($expire_notify) { reset($expire_notify); $fn = next($expire_notify); $savem = $conn->SetFetchMode(ADODB_FETCH_NUM); $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time}"; $rs =& $conn->Execute($sql); ADODB_Session::_dumprs($rs); $conn->SetFetchMode($savem); if ($rs) { $conn->StartTrans(); $keys = array(); while (!$rs->EOF) { $ref = $rs->fields[0]; $key = $rs->fields[1]; $fn($ref, $key); $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key)); $rs->MoveNext(); } $rs->Close(); $conn->CompleteTrans(); } } else { if (1) { $sql = "SELECT sesskey FROM {$table} WHERE expiry < {$time}"; $arr =& $conn->GetAll($sql); foreach ($arr as $row) { $sql2 = "DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'); $conn->Execute($sql2, array($row[0])); } } else { $sql = "DELETE FROM {$table} WHERE expiry < {$time}"; $rs =& $conn->Execute($sql); ADODB_Session::_dumprs($rs); if ($rs) { $rs->Close(); } } if ($debug) { ADOConnection::outp("<p><b>Garbage Collection</b>: {$sql}</p>"); } } // suggested by Cameron, "GaM3R" <*****@*****.**> if ($optimize) { $driver = ADODB_Session::driver(); if (preg_match('/mysql/i', $driver)) { $sql = "OPTIMIZE TABLE {$table}"; } if (preg_match('/postgres/i', $driver)) { $sql = "VACUUM {$table}"; } if (!empty($sql)) { $conn->Execute($sql); } } if ($sync_seconds) { $sql = 'SELECT '; if ($conn->dataProvider === 'oci8') { $sql .= "TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')"; } else { $sql .= $conn->sysTimeStamp; } $sql .= " FROM {$table}"; $rs =& $conn->SelectLimit($sql, 1); if ($rs && !$rs->EOF) { $dbts = reset($rs->fields); $rs->Close(); $dbt = $conn->UnixTimeStamp($dbts); $t = time(); if (abs($dbt - $t) >= $sync_seconds) { $msg = __FILE__ . ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . " database={$dbt} ({$dbts}), webserver={$t} (diff=" . abs($dbt - $t) / 60 . ' minutes)'; error_log($msg); if ($debug) { ADOConnection::outp("<p>{$msg}</p>"); } } } } return true; }
require_once '../session/adodb-session.php'; $encryption = array('', 'adodb-encrypt-mcrypt.php', 'adodb-encrypt-md5.php', 'adodb-encrypt-ordcrypt.php', 'adodb-encrypt-secret.php', 'adodb-encrypt-sha1.php'); $encryption_object = array('', 'ADODB_Encrypt_MCrypt', 'ADODB_Encrypt_MD5', 'ADODB_Encrypt_OrdCrypt', 'ADODB_Encrypt_Secret', 'ADODB_Encrypt_SHA1'); $encryption_name = array('None', 'MCrypt', 'MD5', 'OrdCrypt', 'Secret', 'SHA1'); $compression = array('', 'adodb-compress-bzip2.php', 'adodb-compress-gzip.php'); $compression_object = array('', 'ADODB_Compress_Bzip2', 'ADODB_Compress_Gzip'); $compression_name = array('None', 'Bzip2', 'Gzip'); if ($_POST['encrypt'] > 0) { require_once ADODB_SESSION . '/' . $encryption[$_POST['encrypt']]; $object = $encryption_object[$_POST['encrypt']]; ADODB_Session::filter(new $object()); } if ($_POST['compress'] > 0) { require_once ADODB_SESSION . '/' . $compression[$_POST['compress']]; $object = $compression_object[$_POST['compress']]; ADODB_Session::filter(new $object()); } $db = ADONewConnection($_POST['databasetype']); $db->createdatabase = true; $result = $db->Connect($_POST['dbhost'], $_POST['dbusername'], $_POST['dbpassword'], $_POST['databasename']); if (!$result) { die("Could not connect to the database."); } $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; function ExpiredSession($expireref, $sesskey) { echo "Session USERID: {$expireref} - expired<br>"; echo "Session Key: {$sesskey}<br><br>"; } if ($_POST['databasetype'] == 'mysql' || $_POST['databasetype'] == 'mysqli' || $_POST['databasetype'] == 'mysqlt') { $res = $db->Execute("DROP TABLE IF EXISTS `sessions`");
<?php /* V5.04 13 Feb 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved. Contributed by Ross Smith (adodb@netebb.com). Released under both BSD license and Lesser GPL library license. Whenever there is any discrepancy between the two licenses, the BSD license will take precedence. Set tabs to 4 for best viewing. */ /* This file is provided for backwards compatibility purposes */ if (!defined('ADODB_SESSION')) { require_once dirname(__FILE__) . '/adodb-session.php'; } require_once ADODB_SESSION . '/adodb-encrypt-md5.php'; ADODB_Session::filter(new ADODB_Encrypt_MD5());
/** Loads config vars, and sets general stuff as PATH */ private function initializeEnviromental() { $this->expiretime= $this->config->get('expires', 'metadata'); $this->allowcache= true; if ($this->config->get('allow-cache', 'main') == "false") { $this->allowcache= false; } # set headers //header('Date: '.gmdate('D, d M Y H:i:s \G\M\T', time())); header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T', time())); //header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + $this->expiretime)); # set path $this->filesdir = $this->config->get('filesdir', 'location'); $this->cachedir = $this->config->get('cachedir', 'location'); // (hace algo?) // $path= ini_get("include_path"); // if (trim($path) != '') // $path .= PATH_SEPARATOR.$this->filesdir; // else // $path= $this->filesdir; // ini_set("include_path", $path); # directorios // $this->cachedir= $this->filesdir.DIRECTORY_SEPARATOR.'archivos'.DIRECTORY_SEPARATOR.'cache'; $this->enginedir = $this->filesdir.DIRECTORY_SEPARATOR.'oob'; $this->libsdir = $this->filesdir.DIRECTORY_SEPARATOR.'oob'.DIRECTORY_SEPARATOR.'librerias'; # set title & metadata $this->title= $this->config->get('title', 'main'); $this->description= $this->config->get('description', 'metadata'); $this->keywords= $this->config->get('keywords', 'metadata'); $this->author= $this->config->get('author', 'metadata'); # set webdir $this->webaddress= $this->config->get('webaddress', 'location'); $this->adminaddress= $this->config->get('adminaddress', 'location'); #set debug mode $this->debug= false; if ($this->config->get('debug', 'main') == "true") { $this->debug= true; } # To avoid sending 2 cookies, we disable the session.cookie from php. ini_set("session.use_cookies", "0"); /* we must send the dB connection object to the session handler!, and try to use the same session if previously existed! */ if ($this->mode != 'cron') { // @todo : update session manager to use something better $GLOBALS['ADODB_SESS_CONN'] = $this->db; ADODB_Session :: lifetime($this->expiretime); // warn: si el porcentaje gc es muy alto, puede q nunca mueran las sesiones if (!isset ($_COOKIE["OOB_Session"])) { session_start(); // expire on about 15 days, expire time handled by session setcookie("OOB_Session", session_id(), time() + 1209600, "/"); } else { session_id($_COOKIE["OOB_Session"]); session_start(); } // cross-site-scripting protection (phpsecurity consortium, recomendation) // fixed to work when the client does not provide user/agent. if (isset ($_SERVER['HTTP_USER_AGENT'])) $agent = $_SERVER['HTTP_USER_AGENT']; else $agent = "unknown"; if (isset ($_SESSION['HTTP_USER_AGENT'])) { if ($_SESSION['HTTP_USER_AGENT'] != md5($agent)) { // si el agente cambia, la sesion se muere session_destroy(); //throw new OOB_exception("Sesion no válida desde {$agent}", "403", "Sus datos de comprobación de sesión no concuerdan, vuelva a ingresar al sitio.", true); } } else { $_SESSION['HTTP_USER_AGENT']= md5($agent); } } }