我有以下代码:
<html>
<head>
<title><?php echo $GLOBALS['L']['title']; ?></title>
</head>
<body>
<ul id="language-selection">
<li><a href="index.php?lang=english">English</a></li>
<li><a href="index.php?lang=french">French</a></li>
</ul>
<h1><?php echo $GLOBALS['L']['h1']; ?></h1>
<p><?php echo $GLOBALS['L']['p1']; ?></p>
<ul id="language-selection">
<li><a href="about.php">About Page</a></li>
<li><a href="contact.php">Contact Page</a></li>
</ul>
</body>
</html>
set_locale.php:
<?php
/*
* File: set_locale.php
*/
// Get the language from the query string, or set a default.
($language = @$_GET['lang']) or $language = 'english';
// Set up a list of possible values, and make sure the
// selected language is valid.
$allowed_locales = array('english', 'french');
if(!in_array($language, $allowed_locales))
$language = 'english'; // Set default if it is invalid.
// Inlclude the selected language
include "locale/$language.php";
// Make it global, so it is accessible everywhere in the code.
$GLOBALS['L'] = $locale;
?>
它工作正常,但如果我单击about.php
和contact.php
链接。页面返回默认语言:英语。about.php
当我点击或contact.php
结束时,我该怎么做:
about.php?lang=english
contact.php?lang=french
分别,换句话说,我希望 URL 记住?lang=
结尾。最好的方法是什么?