Results 1 to 5 of 5

Thread: [RESOLVED] noob nquestion: Variables scope

  1. #1

    Thread Starter
    Member Matias's Avatar
    Join Date
    Jun 2005
    Location
    Buenos Aires, Argentina.
    Posts
    43

    Resolved [RESOLVED] noob nquestion: Variables scope

    I'm trying to develop a web with 2 languages (english-spanish), first, i should learn english (i know ) but well, i want to know which is the scope of variables that get passed by the browser. This is my home.php:

    HTML Code:
    <?PHP
    
    require_once('include_dir/load_smarty.php');
    
    if($_GET["lang"]=="es")
           {
                $smarty->assign("welcome","Bienvenido al sitio web de DBB");
                $smarty->assign("menu","menu_es.tpl");
             }
    elseif($_GET["lang"] =="en")
            {
                $smarty->assign("welcome","Welcome to the DBB Website");
                $smarty->assign("menu","menu_en.tpl");
             }
    
    $smarty->display("home.tpl");
    
    ?>
    the superglobal $_GET["lang"] is available to subsecuents php scripts? Or just to that particular one. If it isn't, who do i keep that value to the rest of the web, without asking for the language again?


    Thanks in advance, Matias.-
    ... and the rivers shall open for the righteous, and the rivers shall open for the righteous, and rivers shall open for the righteous, someday ....

  2. #2
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    Re: noob nquestion: Variables scope

    If it isn't... then my idea would be to add that to the html as a hidden field.

    but perhaps there are other ways of getting this, not sure though... for now i think that will have to do.

  3. #3
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: noob nquestion: Variables scope

    What you could do is have separate language files, each language file can be a template that defines all verbiage used in your php application. For example, if you have a welcome message, you might define a special variable called $strWelcome to contain that message. In your code, you just echo the variable name, in this case, $strWelcome to display it as needed. Changing the language to display (English, Spanish, etc..) would be only a matter of including the correct php file. You could do this using a drop-down box of some sort that then tells your application which language to use, and thereby which php language file to include...

    Just an idea.


    To answer your question, you could use a session object to store the value of $_GET, and then retrieve it later when needed from the session.

    For more information on sessions, see http://us3.php.net/manual/en/reserve...iables.session and http://us3.php.net/manual/en/ref.session.php


    PS. I am really wanting to learn spanish. I know some simple phrases already.
    Last edited by nkad; Jul 26th, 2005 at 11:05 PM.

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765

    Re: noob nquestion: Variables scope

    Quote Originally Posted by Matias
    the superglobal $_GET["lang"] is available to subsecuents php scripts? Or just to that particular one. If it isn't, who do i keep that value to the rest of the web, without asking for the language again?-
    If I understand correctly, you can store the language in a cookie, using Sessions (which stores it serverside while the browser is opened, or in a cookie). Using a hidden form element won't work since you have to keep submitting a form to pass it between pages.

    $_GET is only for one page and is then forgotten.

    For ease of use, Cookies are quite simple, but Sessions are the proper way to do it I think, but can be alittle bit more complicated (gotta start a session and figure out why the feck the server won't make cookies! ).

    I think thats right. Hope that helps.
    Don't Rate my posts.

  5. #5

    Thread Starter
    Member Matias's Avatar
    Join Date
    Jun 2005
    Location
    Buenos Aires, Argentina.
    Posts
    43

    Re: noob nquestion: Variables scope

    Quote Originally Posted by Pc_Madness
    $_GET is only for one page and is then forgotten.
    too bad, well, i guess i'll start reading about sessions.


    thanks to everybody!!
    ... and the rivers shall open for the righteous, and the rivers shall open for the righteous, and rivers shall open for the righteous, someday ....

Posting Permissions

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



Click Here to Expand Forum to Full Width