Cookie to change language

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&ntilde;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.

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’].

Ah, yes - many thanks.

G :slight_smile: