remember language

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
myplaces
Forum Newbie
Posts: 11
Joined: Wed Nov 12, 2008 3:25 pm

remember language

Post by myplaces »

I have script (below).
i have file index.php which contains this script. then I have folder language which contains files en.php and ru.php. Both the files also contains the script.
Problem is that in such situation script does not work. If en.php and ru.php are blank or contains other code, script works.
What i need to do to get to work the script?
And other problem that Opera does not remember cookie.... FF and IE remember....
What I have to do?


<?php>
$languages = array('en' => 'English',
'ru' => 'Russian');

if (isset($_GET['lang'])) {

$lang = $_GET['lang'];

setcookie('lang', $lang, time()+(3600*24*365));

header("Location: index.php");

}else if (isset($_COOKIE['lang'])) {
$lang = $_COOKIE['lang'];
} else {
$lang = 'en';
}

if (!(in_array($lang, array_keys($languages)))) {
die("ERROR: Bad Language String Provided!");
}

include "language/{$lang}.php";
php?>

<a href="?lang=lv">Russian</a>
<a href="?lang=en">English</a>
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: remember language

Post by panic! »

Try setting the cookie path.
Post Reply