Simple PHP script question

Discussion in 'Web Design and Development' started by carlosbutler, Mar 21, 2009.

  1. carlosbutler macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City
    #1
    I am trying to do some PHP and one thing im trying is to do a site with multiple languages.

    One small part is this below (i just reduced it so that is sort of works, but with the error part in it):

    in the switch section, i am trying to get it so that the page changes with the variable $lan, but i can seem to make it work. the switch cases work fine, but i can seem to get the language part to work. if you notice there is english in the if.... and spanish for the else.... it always goes to spanish. i have tried by also declaring the variable and doing $lan=='gb' and $lan=='es' and that way it will work. but when typing in the address bar www....file.php?page=destinations&lan=uk
    (or es) it doesnt seem to change

    any help thanks!
    carlos
     
  2. kungfu macrumors regular

    Joined:
    Jan 21, 2002
    #2
    unless the server has register globals enabled (which it shouldn't) -- you need to define $lan. ie,

    if ($_GET['lan']) $lan = $_GET['lan']; else $lan = 'gb';
     
  3. carlosbutler thread starter macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City
    #3
    so does this need to be done for anything of this type. as you may have guessed, i have literally just started off PHP today:p
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    You'll also want to make sure $page is defined outside the if..else statements to ensure that it has the proper scope for the switch statement.

    PHP:
    // Making sure that a page is selected
    $page 'abc';
    if (isset(
    $_GET['page'])) {
      
    $page $_GET['page'];
    }
    And as kungfu was trying to say, you need to define what $lan is. Currently it's never set equal to anything so your if statement is comparing against null/undefined.
     
  5. carlosbutler thread starter macrumors 6502a

    carlosbutler

    Joined:
    Feb 24, 2008
    Location:
    London City

Share This Page