Page 1 of 1

Global variables

Posted: Sat Mar 23, 2013 10:50 am
by mblascog
Hi,
I'm new in php and I'd like to know if it's possible to do what I'm trying.
I'm writting a multilanguage web. I've created a global variable that contains a character indicating the language ($lang).

I've got also, an external file that I include in every web, where I've got all the captions, in array, with the values translated, I mean:

$links_array = array('c'=>'EnllaƧos','e'=>'Enlaces','f'=>'Links','a'=>'Links');

In every web I've got a button for every language. In the onclick event, I've got this code:

onclick="<?php $GLOBALS[lang]='c'?>;javascript:window.location.reload();"

With this I want when the user clicks, reload the web with the language chosen.

The captions I've got in the web are like this

Code: Select all

<ul><li><?php echo $link_array[$lang] ?></li></ul>

Thanks very much

Re: Global variables

Posted: Mon Mar 25, 2013 5:38 am
by johnj
I wouldn't use a global variable in this case. Instead, I would just pass that variable as a form variable from page to page or better use a session variable.