Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Global variables

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Global variables

Postby mblascog » Sat Mar 23, 2013 10:50 am

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]<ul><li><?php echo $link_array[$lang] ?></li></ul>

Thanks very much
mblascog
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Feb 26, 2013 12:00 am

Re: Global variables

Postby johnj » 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.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron