I've been trying to create a simple language switcher (Eng & Ger). I've created duplicate fields for each piece of content, ending in _en or _de Then created links for each ending in ?lan=eng and ?lan=de
A test version can be seen at:
http://www.premiergolfacademy.com/aboutTest.php
Everything works up to a point, but when you click the links, which sets a cookie, you only get the correct language when you click again, or refresh. The PHP which select the correct content from the cookie setting is:
<?php if(@$_COOKIE['langCookie'] == "de"): ?>
<?php echo htmlencode($aboutRecord['title_de']) ?>
<?php else: ?>
<?php echo htmlencode($aboutRecord['title_en']) ?>
<?php endif ?>
and the PHP which sets the cookie is:
<?php
function setLanguage ()
{
if(isset($_GET['lan']))
{
if($_GET['lan'] == 'de')
{
setcookie('langCookie','de',time()+60*60*24*365);
}
else
{
setcookie('langCookie','en',time()+60*60*24*365);
}
}
else
{
setcookie('langCookie','en',time()+60*60*24*365);
}
}
function checkLangCookie ()
{
if(isset($_COOKIE['langCookie']))
{
if($_COOKIE['langCookie'] == 'de')
{
setcookie('langCookie','de',time()+60*60*24*365);
}
else
{
setcookie('langCookie','en',time()+60*60*24*365);
}
}
else
{
setcookie('langCookie','de',time()+60*60*24*365);
}
}
checkLangCookie();
setLanguage();
?>
I'm sure this part is the problem - would anyone be able to help?