开发者

How to trigger language switcher

Hi i would like to set several languages on my site, a have good looking php script but i have a problem with trigger it, my knowledge of php is very poor

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';
}

and my 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>

what I should put here to trigger script

<div id="languages">
<a href="index.php?//?????????//"><img src="images/en.png" /></a>
&l开发者_运维问答t;a href="index.php?//?????????//"><img src="images/pl.png" /></a>
</div>


<a href="index.php?lang=En"><img src="images/en.png" /></a>
<a href="index.php?lang=Pl"><img src="images/pl.png" /></a>


And, for the sake of all that is holy, please check that the vale of $_GET['lang'] is acceptable before putting it in the cookie:

if (in_array($_GET['lang'], array('pl','en','fr')) {
    $langID = $_GET['lang'];
} else {
    // throw an error
}

If you don't do this your script will not be secure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜