Professional Web Applications Themes

bilingual website switch with PHP does not work. Anybody an idea? - PHP Development

Hi, I have a little issue with the following piece of code. I am building an web application which needs to be in two lanugages (English and Danish). I would like to use a session to keep for a single user the right language. However, this seems to be a problem. For some reason, I do not manage to get the switch working. Is there anybody, who has an idea how to solve this? Many thanks in advance from Copenhagen Denmark. Jochem ============ The code: ============ <?php session_start(); if (isset($_GET["changelanguage"])){ $language = $_GET["changelanguage"]; session_register("language"); } if (session_is_registered(language)){ if($_SESSION["language"] == 'dansk'){ ...

  1. #1

    Default bilingual website switch with PHP does not work. Anybody an idea?

    Hi,

    I have a little issue with the following piece of code. I am building
    an web application which needs to be in two lanugages (English and
    Danish). I would like to use a session to keep for a single user the
    right language. However, this seems to be a problem. For some reason, I
    do not manage to get the switch working.

    Is there anybody, who has an idea how to solve this?

    Many thanks in advance from Copenhagen Denmark.

    Jochem

    ============
    The code:
    ============

    <?php
    session_start();

    if (isset($_GET["changelanguage"])){
    $language = $_GET["changelanguage"];
    session_register("language");
    }

    if (session_is_registered(language)){
    if($_SESSION["language"] == 'dansk'){
    echo "dansk (switch to <a href='". $_SERVER["PHP_SELF"]
    .."?changelanguage=English'>English</a>)";
    }else{
    echo "English (skift til <a href='". $_SERVER["PHP_SELF"]
    .."?changelanguage=dansk'>dansk</a>)";
    }
    }else{
    $language = "English";
    session_register("language");
    }
    ?>

    Jochem Guest

  2. #2

    Default Re: bilingual website switch with PHP does not work. Anybody an idea?

     
     

    session_is_registered() takes a string argument. This should be:

    if (session_is_registered("language")){


    ---
    Steve

    Steve Guest

  3. #3

    Default Re: bilingual website switch with PHP does not work. Anybody an idea?

    Steve, Thanks for your response. With or without quotation marks I get
    into the if statement, so that does not seem to be the real problem. I
    have more issues with updating the $_SERVER["language"] if the $_GET is
    set; in the very first part of the script. This:

    if (isset($_GET["changelanguage"])){
    $language = $_GET["changelanguage"];
    session_register("language");
    }

    For some reason, my script does not replace the existing with a new. I
    also tried to empty it with session_unset and session_unregister. Any
    idea what could be wrong there?

    Jochem Guest

  4. #4

    Default Re: bilingual website switch with PHP does not work. Anybody an idea?


    (GoogleGroups trashed my original draft reply after I zapped my cookies
    whilst testing this 8-)

    Quick summary: check the case of $_GET["changelanguage"]: "dansk" or
    "Dansk"? You must be consistent throughout, or force the case before
    comparisons.

    ---
    Steve

    Steve Guest

Similar Threads

  1. Video stops playing if I switch to other website
    By jbclem in forum Macromedia Flash Player
    Replies: 0
    Last Post: May 24th, 09:07 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139