Variables being APPENDING in URL and Address bar. Why ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • david.hunter@gmail.com

    Variables being APPENDING in URL and Address bar. Why ?

    Hi - my site is bilingual.
    I have two language files that look like this :
    en.inc
    define(HELLO, 'Hello');
    fr.inc
    define(HELLO, 'Bonjour');

    Then my php/html looks like this:
    <h3><?php echo HELLO ?></h3>

    In each page I check and/or set the language :
    index.php :
    $lang='en';
    require('langua ges/set_language.ph p');

    set_language.ph p :
    if (isset($_GET['lang'])) {
    $lang = $_GET['lang']; }
    require("{$lang }.inc");

    I have a hyperlink in the footer so that the user can toggle between
    languages. The toggle works, but the language parameter is being
    APPENDED into the URL and in the address bar of the browser - like this
    :
    &lang=fr&lang=e n&lang=fr&lang= en&lang=fr

    Why is this happening and how can I stop it ?

    Here is my footer.php code :
    <a href="http://website.com/<?php echo
    $_SERVER['SCRIPT_NAME'] ?>?<?php echo $_SERVER['QUERY_STRING']
    ?>&lang=<?php echo $toggle ?>"><?php echo MENU_TOGGLE ?></a>

    THANK YOU!

    I know it's not practical for people to be going back and forth between
    languages - but this problem is still annoying the heck out of me!

  • Jerry Stuckle

    #2
    Re: Variables being APPENDING in URL and Address bar. Why ?

    david.hunter@gm ail.com wrote:[color=blue]
    > Hi - my site is bilingual.
    > I have two language files that look like this :
    > en.inc
    > define(HELLO, 'Hello');
    > fr.inc
    > define(HELLO, 'Bonjour');
    >
    > Then my php/html looks like this:
    > <h3><?php echo HELLO ?></h3>
    >
    > In each page I check and/or set the language :
    > index.php :
    > $lang='en';
    > require('langua ges/set_language.ph p');
    >
    > set_language.ph p :
    > if (isset($_GET['lang'])) {
    > $lang = $_GET['lang']; }
    > require("{$lang }.inc");
    >
    > I have a hyperlink in the footer so that the user can toggle between
    > languages. The toggle works, but the language parameter is being
    > APPENDED into the URL and in the address bar of the browser - like this
    > :
    > &lang=fr&lang=e n&lang=fr&lang= en&lang=fr
    >
    > Why is this happening and how can I stop it ?
    >
    > Here is my footer.php code :
    > <a href="http://website.com/<?php echo
    > $_SERVER['SCRIPT_NAME'] ?>?<?php echo $_SERVER['QUERY_STRING']
    > ?>&lang=<?php echo $toggle ?>"><?php echo MENU_TOGGLE ?></a>
    >
    > THANK YOU!
    >
    > I know it's not practical for people to be going back and forth between
    > languages - but this problem is still annoying the heck out of me!
    >[/color]

    Don't echo the query string.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Syl

      #3
      Re: Variables being APPENDING in URL and Address bar. Why ?

      ARGH!!!! Of course!

      Thanks you so much Jerry - I should have posted my quesiton *hours*
      ago!!!

      Comment

      • Codik

        #4
        Re: Variables being APPENDING in URL and Address bar. Why ?

        david.hunter@gm ail.com napĂ­sal(a):[color=blue]
        > I have a hyperlink in the footer so that the user can toggle between
        > languages. The toggle works, but the language parameter is being
        > APPENDED into the URL and in the address bar of the browser - like this
        > :
        > &lang=fr&lang=e n&lang=fr&lang= en&lang=fr
        >
        > Why is this happening and how can I stop it ?
        >
        > Here is my footer.php code :
        > <a href="http://website.com/<?php echo
        > $_SERVER['SCRIPT_NAME'] ?>?<?php echo $_SERVER['QUERY_STRING']
        > ?>&lang=<?php echo $toggle ?>"><?php echo MENU_TOGGLE ?></a>[/color]

        Good day.

        It is happening because variable $_SERVER['QUERY_STRING'] contains
        &lang and You want add next in Your script. You must filter it. You can
        use this (footer.php):
        <?php
        $new_qs = preg_replace("/(.*&?lang=)(?:. *?(&.*)|(?:.*))/",
        "\\1".$toggle." \\2", $_SERVER['QUERY_STRING']);

        echo '<a
        href="http://website.com/'.$_SERVER['SCRIPT_NAME'].'?'.$new_qs.'" >'.MENU_TOGGLE. '</a>';
        ?>

        --
        When my English is bad, sorry.

        Comment

        • Jerry Stuckle

          #5
          Re: Variables being APPENDING in URL and Address bar. Why ?

          Syl wrote:[color=blue]
          > ARGH!!!! Of course!
          >
          > Thanks you so much Jerry - I should have posted my quesiton *hours*
          > ago!!!
          >[/color]

          Sometimes you stare at the problem so long you can't see it. Then
          someone else comes along and points out the obvious.

          Don't know how many times it's happened to me! :-)

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...