我已经对这个问题有疑问,但还有一个问题属于$_GET和header-function:
我有一个多语种网站.当调用不存在的页面时,.htaccess将引用根目录中的404.php.
.htaccess看起来像这样:
ErrorDocument 404 /404.php
根方向的404.php只是查看SESSION或COOKIE设置的默认语言,并引用语言子目录/language/404.php
根404.php看起来像这样:
include_once "scripts/pref_language.php";
if (isset ($_GET['uri']) ){
$get = $_GET['uri'];
header("Location: /$pref_language/404.php?uri=$get");
exit;
}
$url = urlencode($_SERVER['REQUEST_URI']);
header("Location: /$pref_language/404.php?uri=$url");
引用语言子目录,发布的URL看起来像参数uri仍然不同:
http://www.example.com/english/404.php?uri=somedata
或用另一种语言:
http://www.example.com/german/404.php?uri=somedata
/english/404.php的代码如下所示:
error_reporting(E_ALL);
ob_start();
session_start();
header ("Content-Type: text/html; charset=utf-8");
include_once "../scripts/db_connect.php";
include_once "../scripts/functions.php";
include_once "../scripts/browser_identification.php";
include_once "../scripts/pref_language.php";
...some text variables in its specific language
include_once "../templates/template_404.php";
?>
模板只是一些HTML样式.将包含在template_404.php中的页脚是发送数据的主要吸引力.在该页脚中,可以选择更改语言设置并在语言路径之间切换.如果将提交表单,则会更改SESSION和COOKIE,并且页面将启动标题功能.
所以这是来自页脚的代码:
if (isset($_GET['uri']) ) {
$uri = urlencode($_GET['uri']);
echo "TEST URI: $uri";
}
...
$basename = basename($_SERVER['SCRIPT_NAME'], ".php");
if ($basename === "index") {
$form_action = rtrim($_SERVER['PHP_SELF'], 'index.php');
} else{
$form_action = htmlentities($_SERVER['PHP_SELF']);
}
...
if ( isset($_POST['pref_lang']) ) {
$content = $_POST['pref_lang'];
if ($content === "german") {
if ($basename === "about") {
$basename = "info";
} else if ($basename === "contact") {
$basename = "kontakt";
}
}
$_SESSION['pref_language'] = $_POST['pref_lang'];
setcookie('pref_language', '', time()- 999999, '/', '.example.de' );
setcookie('pref_language', $content, time()+60*60*24*365, '/', '.example.de');
if ($basename === "404"){
header("Location: ../$content/404.php?uri=$uri");
} else {
header("Location: ../$content/$basename");
}
}
?>
german
问题是当页面的URL为
http://www.example.com/**english**/404.php?uri=somedata
我将提交$_POST将语言更改为德语,如:
http://www.example.com/**german**/404.php?uri=somedata
例如$_GET [‘uri’]将为空,URL如下所示:
http://www.example.com/**german**/404.php?uri=
启动头功能后.我试图回应那条线而不是标题,我将收到一条消息,表明uri未定义.
Undefined variable: uri in /customers/7/4/1/example.com/httpd.www/scripts/footer_en.php on line 102
Location: ../english/404.php?uri=
奇怪的是,当我在发送$_POST之前调用页面并查看网站的源代码时,变量$uri将正确地读出$_GET参数但稍后它在标题中不再起作用功能.问题是为什么这不起作用?
如果有人能告诉我如何处理这个问题,那就太好了.我真的很感激.
非常感谢.
更新:
我试图将$_GET参数保存到SESSION中但是当发布表单并重定向到另一个语言站点时,SESSION的内容似乎是错误的,因为它不是$_GET参数而不是它将是什么东西是什么来自html头部的css链接,如css / colorbox.css
目前我尝试通过将表单操作设置为:
...
if ($basename === "index") {
$form_action = rtrim($_SERVER['PHP_SELF'], 'index.php');
}
if ($basename === "404") {
$form_action = "";
}
if ($basename !== "index" AND $basename !== "404") {
$form_action = htmlentities($_SERVER['PHP_SELF']);
}
...
" method="post">englisch