Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Save lang to cookie

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@164 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit 222fc78685769bbaccdf0383e5d710c77fa9dc60 1 parent e9ee9b8
jakubvrana authored
Showing with 11 additions and 10 deletions.
  1. +7 −7 _compile.php
  2. +4 −3 lang.inc.php
View
14 _compile.php
@@ -14,9 +14,9 @@ function remove_lang($match) {
function put_file($match) {
$return = file_get_contents($match[4]);
if ($match[4] == "./lang.inc.php") {
- if (!$_SESSION["lang"]) {
+ if (!$_COOKIE["lang"]) {
$return = str_replace("\tif (\$number === false) { // used in _compile.php\n\t\treturn (\$translation ? \$translation : \$idf);\n\t}\n", "", $return);
- } elseif (preg_match("~case '$_SESSION[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2)) {
+ } elseif (preg_match("~case '$_COOKIE[lang]': (.*) break;~", $return, $match2) || preg_match("~default: (.*)~", $return, $match2)) {
return "$match[1]\nfunction lang(\$ar, \$number) {\n\t$match2[1]\n\treturn \$ar[\$pos];\n}\n$match[5]";
}
}
@@ -35,7 +35,7 @@ function put_file($match) {
error_reporting(E_ALL & ~E_NOTICE);
if ($_SERVER["argc"] > 1) {
- $_SESSION["lang"] = $_SERVER["argv"][1];
+ $_COOKIE["lang"] = $_SERVER["argv"][1];
include "./lang.inc.php";
if ($_SERVER["argc"] != 2 || !in_array($_SERVER["argv"][1], lang())) {
echo "Usage: php _compile.php [lang]\nPurpose: Compile phpMinAdmin[-lang].php from index.php.\n";
@@ -44,14 +44,14 @@ function put_file($match) {
}
$filename = "phpMinAdmin.php";
$file = file_get_contents("index.php");
-if ($_SESSION["lang"]) {
- $filename = "phpMinAdmin-$_SESSION[lang].php";
+if ($_COOKIE["lang"]) {
+ $filename = "phpMinAdmin-$_COOKIE[lang].php";
}
$file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
-if ($_SESSION["lang"]) {
+if ($_COOKIE["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("<?php switch_lang(); ?>\n", "", $file);
- $file = str_replace("<?php echo get_lang(); ?>", $_SESSION["lang"], $file);
+ $file = str_replace("<?php echo get_lang(); ?>", $_COOKIE["lang"], $file);
}
$file = str_replace("favicon.ico", "data:image/x-icon;base64," . base64_encode(file_get_contents("favicon.ico")), $file);
$file = str_replace('<link rel="stylesheet" type="text/css" href="default.css" />', "<style type='text/css'>\n" . file_get_contents("default.css") . "</style>", $file);
View
7 lang.inc.php
@@ -152,11 +152,12 @@ function switch_lang() {
}
if (isset($_GET["lang"])) {
- $_SESSION["lang"] = $_GET["lang"];
+ setcookie("lang", $_GET["lang"], strtotime("+1 month"));
+ $_COOKIE["lang"] = $_GET["lang"];
}
-if (strlen($_SESSION["lang"])) {
- $LANG = $_SESSION["lang"];
+if (strlen($_COOKIE["lang"])) {
+ $LANG = $_COOKIE["lang"];
} else {
$langs = lang();
$LANG = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
Please sign in to comment.
Something went wrong with that request. Please try again.