Improve session management

This commit is contained in:
Jakub Vrana 2012-08-19 13:42:13 -07:00
parent c9da3ccb51
commit 5e0038b62d
6 changed files with 16 additions and 8 deletions

View file

@ -271,11 +271,13 @@ if (!defined("DRIVER")) {
$return = &get_session("dbs");
if ($return === null) {
if ($flush) {
restart_session();
ob_flush();
flush();
}
$return = get_vals($connection->server_info >= 5 ? "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA" : "SHOW DATABASES"); // SHOW DATABASES can be disabled by skip_show_database
$databases = get_vals($connection->server_info >= 5 ? "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA" : "SHOW DATABASES"); // SHOW DATABASES can be disabled by skip_show_database
restart_session();
$return = $databases;
stop_session();
}
return $return;
}

View file

@ -76,8 +76,8 @@ include "../adminer/include/auth.inc.php";
include "./include/connect.inc.php";
include "./include/editing.inc.php";
session_cache_limiter(""); // to allow restarting session
if (!ini_bool("session.use_cookies") || @ini_set("session.use_cookies", false) !== false) { // @ - may be disabled
session_cache_limiter(""); // to allow restarting session
session_write_close(); // improves concurrency if a user opens several pages at once, may be restarted later
}

View file

@ -77,6 +77,7 @@ document.body.className = document.body.className.replace(/ nojs/, ' js');
if (DB != "" && $databases && !in_array(DB, $databases, true)) {
$databases = null;
}
stop_session();
if ($error) {
echo "<div class='error'>$error</div>\n";
}

View file

@ -396,6 +396,15 @@ function restart_session() {
}
}
/** Stop session if it would be possible to restart it later
* @return null
*/
function stop_session() {
if (!ini_bool("session.use_cookies")) {
session_write_close();
}
}
/** Get session variable for current server
* @param string
* @return mixed

View file

@ -189,7 +189,6 @@ if ($_POST && !$error) {
$table_name = $adminer->tableName($table_status);
page_header(lang('Select') . ": $table_name", $error);
session_write_close();
$set = null;
if (isset($rights["insert"])) {

View file

@ -39,9 +39,6 @@ if (!$error && $_POST) {
}
}
$space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\n]*\n|--\n)";
if (!ini_bool("session.use_cookies")) {
session_write_close();
}
$delimiter = ";";
$offset = 0;
$empty = true;
@ -136,7 +133,7 @@ if (!$error && $_POST) {
if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) {
restart_session();
set_session("dbs", null); // clear cache
session_write_close();
stop_session();
}
if (!$_POST["only_errors"]) {
echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n";