Exemple #1
0
    return Database::prepare("SELECT session_data FROM `##session` WHERE session_id=?")->execute(array($id))->fetchOne();
}, function ($id, $data) {
    // Only update the session table once per minute, unless the session data has actually changed.
    Database::prepare("INSERT INTO `##session` (session_id, user_id, ip_address, session_data, session_time)" . " VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP))" . " ON DUPLICATE KEY UPDATE" . " user_id      = VALUES(user_id)," . " ip_address   = VALUES(ip_address)," . " session_data = VALUES(session_data)," . " session_time = CURRENT_TIMESTAMP - SECOND(CURRENT_TIMESTAMP)")->execute(array($id, (int) Auth::id(), WT_CLIENT_IP, $data));
    return true;
}, function ($id) {
    Database::prepare("DELETE FROM `##session` WHERE session_id=?")->execute(array($id));
    return true;
}, function ($maxlifetime) {
    Database::prepare("DELETE FROM `##session` WHERE session_time < DATE_SUB(NOW(), INTERVAL ? SECOND)")->execute(array($maxlifetime));
    return true;
});
Session::start(array('gc_maxlifetime' => Site::getPreference('SESSION_TIME'), 'cookie_path' => parse_url(WT_BASE_URL, PHP_URL_PATH)));
if (!Auth::isSearchEngine() && !Session::get('initiated')) {
    // A new session, so prevent session fixation attacks by choosing a new PHPSESSID.
    Session::regenerate(false);
    Session::put('initiated', true);
} else {
    // An existing session
}
// Set the tree for the page; (1) the request, (2) the session, (3) the site default, (4) any tree
foreach (array(Filter::post('ged'), Filter::get('ged'), Session::get('GEDCOM'), Site::getPreference('DEFAULT_GEDCOM')) as $tree_name) {
    $WT_TREE = Tree::findByName($tree_name);
    if ($WT_TREE) {
        Session::put('GEDCOM', $tree_name);
        break;
    }
}
// No chosen tree?  Use any one.
if (!$WT_TREE) {
    foreach (Tree::getAll() as $WT_TREE) {