SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    <$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>';
    else
      echo 
    '<a href="changelang.php?lang=en">english</a>'
    and changelang.php is
    PHP Code:
    setcookie('lang'$_REQUEST['lang'], time()+31536000"/");
    header("Location:".$_SERVER['HTTP_REFERER']); 
    I'm just wondering if having the variable and cookie name the same (ie lang) is what's wrong.
    blessed are the cracked for they let in the light

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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'].

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2002
    Location
    Italy
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, yes - many thanks.

    G
    blessed are the cracked for they let in the light


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •