Global variables

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Sat Mar 23, 2013 10:50 am

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

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Mon Mar 25, 2013 5:38 am

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.

Post Reply