Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
    define('ADODB_SESSION_OPTIMIZE', $optimize);
}
define('ADODB_SESSION_SYNCH_SECS', $sync_seconds);
if (class_exists('ADODB_Session')) {
    ADODB_Session::clob($clob);
    ADODB_Session::dataFieldName($data_field_name);
    ADODB_Session::database($database);
    ADODB_Session::debug($debug);
    ADODB_Session::driver($driver);
    ADODB_Session::filter($filters);
    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'])) {
Exemplo n.º 7
0
}
// 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();