gandalf458 — 2010-08-06T06:08:08-04:00 — #1
I have a cookie to store the user's language selection (there's only Spanish or English). The site starts out okay (in Spanish) and if I change the language to English it changes BUT I can't then get back to Spanish. The code is simple and similar to that which I used to change style sheets, but I cannot see what I'm doing wrong. My code is
<$lang = "es";
if ( isset($_COOKIE['lang']) ) $lang = $_COOKIE['lang'];
$php_self = $_SERVER['PHP_SELF'];
if ( $lang == 'en' )
echo '<a href="changelang.php?lang=es">español</a>';
echo '<a href="changelang.php?lang=en">english</a>';
and changelang.php is
setcookie('lang', $_REQUEST['lang'], time()+31536000, "/");
I'm just wondering if having the variable and cookie name the same (ie lang) is what's wrong.
immerse — 2010-08-06T07:45:26-04:00 — #2
It might be because you're using $_REQUEST['lang'].
$REQUEST contains GET, POST and COOKIE (I'm not sure which has precedence, but COOKIE might be overriding GET in the REQUEST array). Try changing it to $GET['lang'].
gandalf458 — 2010-08-06T08:12:27-04:00 — #3
Ah, yes - many thanks.