[RESOLVED] noob nquestion: Variables scope
I'm trying to develop a web with 2 languages (english-spanish), first, i should learn english (i know :D ) 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.-
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. :D
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.
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! :p). :)
I think thats right. Hope that helps. :)
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!!