]> git.joonet.de Git - adminer.git/commitdiff
Redirect function
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 3 Jul 2007 06:48:18 +0000 (06:48 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 3 Jul 2007 06:48:18 +0000 (06:48 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@15 7c3ca157-0c34-0410-bff1-cbf682f78f5c

auth.inc.php
create.inc.php
database.inc.php
edit.inc.php
functions.inc.php
sql.inc.php

index 66f1857d6fad3e732a4f16437cf773ff5809a314..cdd19eb1187c1d52c59378681a0225378deebb59 100644 (file)
@@ -2,7 +2,7 @@
 if (isset($_POST["server"])) {
        $_SESSION["username"] = $_POST["username"];
        $_SESSION["password"] = $_POST["password"];
-       header("Location: " . ((string) $_GET["server"] === $_POST["server"] ? preg_replace('~(\\?)logout=&|[?&]logout=~', '\\1', $_SERVER["REQUEST_URI"]) : preg_replace('~^[^?]*/([^?]*).*~', '\\1' . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : '') . (SID ? (strlen($_POST["server"]) ? "&" : "?") . SID : ""), $_SERVER["REQUEST_URI"])));
+       header("Location: " . ((string) $_GET["server"] === $_POST["server"] ? preg_replace('~(\\?)logout=&|[?&]logout=~', '\\1', $_SERVER["REQUEST_URI"]) : preg_replace('~^[^?]*/([^?]*).*~', '\\1' . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : '') . (strlen(SID) ? (strlen($_POST["server"]) ? "&" : "?") . SID : ""), $_SERVER["REQUEST_URI"])));
        exit;
 } elseif (isset($_GET["logout"])) {
        unset($_SESSION["username"]);
index e11204b89fefa79d97584dedd0568a17c917fce1..5d5fbc7c5b9eaf97dd22737cb7fd144be56d5bae 100644 (file)
@@ -23,9 +23,7 @@ if ($_POST) {
                }
        }
        if (mysql_query($query)) {
-               $_SESSION["message"] = $message;
-               header("Location: " . ($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])) . (SID ? "&" . SID : ""));
-               exit;
+               redirect(($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])), $message);
        }
        $error = mysql_error();
 }
index 0129b7eb71240ab00692a90ea607772fefedc748..1c4091f62eb21a461f72d39b3b1790c6cf2f4275 100644 (file)
@@ -2,17 +2,12 @@
 if ($_POST) {
        if ($_POST["drop"]) {
                if (mysql_query("DROP DATABASE " . idf_escape($_GET["db"]))) {
-                       $_SESSION["message"] = lang('Database has been dropped.');
-                       $location = substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . (SID ? SID . "&" : ""), 0, -1);
-                       header("Location: " . (strlen($location) ? $location : "."));
-                       exit;
+                       redirect(substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF), 0, -1), lang('Database has been dropped.'));
                }
        } elseif ($_GET["db"] !== $_POST["name"]) {
                if (mysql_query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'" : ""))) {
                        if (!strlen($_GET["db"])) {
-                               $_SESSION["message"] = lang('Database has been created.');
-                               header("Location: " . substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]) . "&" . (SID ? SID . "&" : ""), 0, -1));
-                               exit;
+                               redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
                        }
                        $result = mysql_query("SHOW TABLES");
                        while ($row = mysql_fetch_row($result)) {
@@ -23,15 +18,11 @@ if ($_POST) {
                        mysql_free_result($result);
                        if (!$row) {
                                mysql_query("DROP DATABASE " . idf_escape($_GET["db"]));
-                               $_SESSION["message"] = lang('Database has been renamed.');
-                               header("Location: " . substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]) . "&" . (SID ? SID . "&" : ""), 0, -1));
-                               exit;
+                               redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
                        }
                }
        } elseif (!$_POST["collation"] || mysql_query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'")) {
-               $_SESSION["message"] = ($_POST["collation"] ? lang('Database has been altered.') : '');
-               header("Location: " . substr($SELF . (SID ? SID . "&" : ""), 0, -1));
-               exit;
+               redirect(substr($SELF, 0, -1), ($_POST["collation"] ? lang('Database has been altered.') : null));
        }
        $eror = mysql_error();
 }
index f918d4e7e59b7ed5808e3aa2b997390a56829b81..593cf4cedebf41c2a44fd6fb0dc89faf626f4c4f 100644 (file)
@@ -27,9 +27,7 @@ if ($_POST) {
                }
        }
        if (mysql_query($query)) {
-               $_SESSION["message"] = $message;
-               header("Location: " . $SELF . "select=" . urlencode($_GET["edit"]) . (SID ? "&" . SID : ""));
-               exit;
+               redirect($SELF . "select=" . urlencode($_GET["edit"]), $message);
        }
        $error = mysql_error();
 }
index 6ad2174308879deafc51ff0d73c0ef7cb5b8f2a9..b7f806c567506f9758df0f5a89ac8b5fec6b837a 100644 (file)
@@ -119,6 +119,17 @@ function engines() {
        return $return;
 }
 
+function redirect($location, $message = null) {
+       if (isset($message)) {
+               $_SESSION["message"] = $message;
+       }
+       if (strlen(SID)) {
+               $location .= (strpos($location, "?") === false ? "?" : "&") . SID;
+       }
+       header("Location: " . (strlen($location) ? $location : "."));
+       exit;
+}
+
 if (get_magic_quotes_gpc()) {
     $process = array(&$_GET, &$_POST);
     while (list($key, $val) = each($process)) {
index 77c14e8b047ef44513137e94f8f6d2e5ee6fb820..d2bad676569b98e53e542579aef3f3037f4ab246 100644 (file)
@@ -2,9 +2,7 @@
 if ($_POST) {
        $result = mysql_query($_POST["query"]); //! multiple commands
        if ($result === true) {
-               $_SESSION["message"] = sprintf(lang('Query executed OK, %d row(s) affected.'), mysql_affected_rows());
-               header("Location: " . $SELF . "sql=" . (SID ? "&" . SID : ""));
-               exit;
+               redirect($SELF . "sql=", sprintf(lang('Query executed OK, %d row(s) affected.'), mysql_affected_rows()));
        }
        $error = mysql_error();
 }