Permalink
Browse files

Improve session restarting

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1227 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 881fbf5 commit be49e08bb47c870ac81ce09285bb34cccaade283 jakubvrana committed Nov 3, 2009
View
@@ -2,6 +2,7 @@
if ($_POST && !$error && !isset($_POST["add_x"])) { // add is an image and PHP changes add.x to add_x
if (DB !== $_POST["name"]) {
// create or rename database
+ restart_session();
unset($_SESSION["databases"][$_GET["server"]]); // clear cache
$dbs = explode("\n", str_replace("\r", "", $_POST["name"]));
$failed = false;
@@ -15,6 +16,7 @@
}
}
if (query_redirect(queries(), ME . "db=" . urlencode($last), lang('Database has been created.'), !strlen(DB), false, $failed)) {
+ //! move triggers
$result = $connection->query("SHOW TABLES");
while ($row = $result->fetch_row()) {
if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
@@ -358,7 +358,7 @@ function selectEmailProcess($where, $foreignKeys) {
* @return string
*/
function messageQuery($query) {
- session_start();
+ restart_session();
$id = "sql-" . count($_SESSION["messages"]);
$_SESSION["history"][$_GET["server"]][DB][] = $query;
return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . shorten_utf8($query, 1000) . '</pre><a href="' . h(ME . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][DB]) - 1)) . '">' . lang('Edit') . '</a></div>';
@@ -92,8 +92,8 @@
include "./include/export.inc.php";
session_cache_limiter(""); // to allow restarting session
-if (@ini_set("session.use_cookies", false) !== false) { // @ - may be disabled
- session_write_close(); // improves concurrency, may be restarted later
+if (!ini_get("session.use_cookies") || @ini_set("session.use_cookies", false) !== false) { // @ - may be disabled
+ session_write_close(); // improves concurrency if a user opens several pages at once, may be restarted later
}
$confirm = " onclick=\"return confirm('" . lang('Are you sure?') . "');\"";
@@ -52,10 +52,6 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
if (strlen(DB) && $databases && !in_array(DB, $databases, true)) {
$databases = null;
}
- if ((isset($databases) && !isset($_GET["sql"])) || !ini_get("session.use_cookies")) {
- // improves concurrency if a user opens several pages at once
- session_write_close();
- }
if ($error) {
echo "<div class='error'>$error</div>\n";
}
@@ -351,7 +351,7 @@ function drop_create($drop, $create, $location, $message_drop, $message_alter, $
$dropped = strlen($name) && ($_POST["dropped"] || queries($drop));
$created = queries($create);
if (!queries_redirect($location, (strlen($name) ? $message_alter : $message_create), $created) && $dropped) {
- session_start();
+ restart_session();
$_SESSION["messages"][] = $message_drop;
}
return $dropped;
@@ -220,7 +220,7 @@ function restart_session() {
*/
function redirect($location, $message = null) {
if (isset($message)) {
- session_start();
+ restart_session();
$_SESSION["messages"][] = $message;
}
header("Location: " . (strlen($location) ? $location : "."));
View
@@ -1,4 +1,5 @@
<?php
+restart_session();
$history = &$_SESSION["history"][$_GET["server"]][DB];
if (!$error && $_POST["clear"]) {
$history = array();
@@ -27,7 +28,7 @@
$space = "(\\s|/\\*.*\\*/|(#|-- )[^\n]*\n|--\n)";
$alter_database = "(CREATE|DROP)$space+(DATABASE|SCHEMA)\\b~isU";
$databases = &$_SESSION["databases"][$_GET["server"]];
- if ((isset($databases) && !preg_match("~\\b$alter_database", $query)) || !ini_get("session.use_cookies")) { // quick check - may be inside string
+ if (!ini_get("session.use_cookies") || (isset($databases) && !preg_match("~\\b$alter_database", $query))) { // quick check - may be inside string
//! false positive with $fp and disabled ini_set() and enabled session.use_cookies
session_write_close();
}

0 comments on commit be49e08

Please sign in to comment.