您好我想在我的网站上设置几种语言,有一个好看的PHP脚本,但我有触发它的问题,我的PHP知识很差
language.php
header ("content-type: text/html; charset=utf-8");
if (isset($_GET['lang'])) {
$langID = $_GET['lang'];
setcookie('lang', $langID, time()+(3600*24*365));
}
elseif (isset($_COOKIE['lang'])) {
$langID = $_COOKIE['lang'];
}
else {
$langID = 'Pl';
}
和我的index.php
<body>
<div id="languages">
<a href="index.php?//?????????//"><img src="images/en.png" /></a>
<a href="index.php?//?????????//"><img src="images/pl.png" /></a>
</div>
<div id="content">
<div id="tresc">
<?php if($langID == 'Pl'): ?>
<div class="editable" id="polska">
<h1>Head</h1>
<p>first land</p>
</div>
<?php else: ?>
<div class="editable" id="angielska">
<h1>Head</h1>
<p>second lang</p>
</div>
<?php endif; ?>
</div>
</div>
</body>
我应该在这里触发脚本
<div id="languages">
<a href="index.php?//?????????//"><img src="images/en.png" /></a>
<a href="index.php?//?????????//"><img src="images/pl.png" /></a>
</div>
答案 0 :(得分:1)
<a href="index.php?lang=En"><img src="images/en.png" /></a>
<a href="index.php?lang=Pl"><img src="images/pl.png" /></a>
答案 1 :(得分:0)
并且,为了所有神圣的事情,请在将它放入cookie之前检查$ _GET ['lang']的值是否可接受:
if (in_array($_GET['lang'], array('pl','en','fr')) {
$langID = $_GET['lang'];
} else {
// throw an error
}
如果您不这样做,您的脚本将不安全。