PHP4 在会话期间包含文件
我正在尝试在我的网页上添加第二语言。我决定对不同的语言使用不同的文件,通过路径区分 - language/pl/projects.ln
包含波兰语文本,language/en/projects.ln
- 英语。这些扩展只是为了区分其他语言文件,内容很简单 php:
$lang["desc"]["fabrics"]["title"] = "MATERIAŁY";
$lang["desc"]["fabrics"]["short_text"] = "Jakiś tam tekst na temat materiałów";
$lang["desc"]["services"]["title"] = "USŁUGI";
$lang["desc"]["services"]["short_text"] = "Jakiś tam tekst na temat usłóg";
然后在索引页面上我像这样使用它:
session_start();
if (isset($_SESSION["lang"])) {
$language = $_SESSION["lang"];
} else {
$language = "pl";
}
include_once("language/$language/projects.ln");
print $lang["desc"]["fabrics"]["title"];
问题是,如果未设置会话变量,则一切正常并且显示数组项内容,但是一旦我更改并设置 $_SESSION["lang"]
就不会显示任何内容。我通过将 print "sth";
放在projects.ln 文件的开头来测试包含本身是否正常工作,并且与 $_SESSION["lang"]< 一起工作都正常/code> 设置和取消设置。
请帮忙。
I am trying to put second language on my webpage. I decided to use different files for different languages told apart by path - language/pl/projects.ln
contains Polish text, language/en/projects.ln
- English. Those extensions are just to tell language files from other, the content is simple php:
$lang["desc"]["fabrics"]["title"] = "MATERIAŁY";
$lang["desc"]["fabrics"]["short_text"] = "Jakiś tam tekst na temat materiałów";
$lang["desc"]["services"]["title"] = "USŁUGI";
$lang["desc"]["services"]["short_text"] = "Jakiś tam tekst na temat usłóg";
And then on the index page I use it like so:
session_start();
if (isset($_SESSION["lang"])) {
$language = $_SESSION["lang"];
} else {
$language = "pl";
}
include_once("language/$language/projects.ln");
print $lang["desc"]["fabrics"]["title"];
The problem is that if the session variable is not set everything works fine and array item content is displayed but once I change and set $_SESSION["lang"]
nothing is displayed. I tested if the include itself works as it should by putting print "sth";
at the beginning of projects.ln file and that works all right both with $_SESSION["lang"]
set and unset.
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能告诉我们这个输出是什么吗:
Can you tell us what does this one output:
会话开始正常,我意外地修复了它。
我将
$_SESSION['lang']
重命名为$_SESSION['curr_lang']
,现在可以正常工作了。看起来它不喜欢具有相同名称的数组和会话变量(?)。Session starts fine and accidentally I managed to fix it.
I renamed
$_SESSION['lang']
to$_SESSION['curr_lang']
and it now works allright. It seams like it didn't like the array and session variable having the same name (?).