Global variable turned on – PHP



I have just moved to a new server and apparently I cannot use global variables as I used to. I would like to reenable this as it was in teh past.

I guess that there is a setting called global_variables that is set to "off" by default. How do I set this to "on"? I have root access on this server so there should be no problem with me being able to change this setting if I knew how.

actually my problem is that first i am able to use $username instead of $_POST[‘username’].
But on another server me not able to access like that
please tell me what changes i have to do

Thanks very much.


You can edit your php configuration, if you have access to your php.ini file (config file).


my advice: keep it like it is. register_globals was turned off because of security reasons (see PHP: Using Register Globals – Manual). and you’re writing much cleaner code when using the apropriate superglobals ($_GET, $_POST, $_COOKIE, …)

if you indeed need global data, you may consider using a class for that (e.g. the abstract registry pattern)



thanks for reply

i have to on global variable

i made changes in php.ini file as register_globals = On

and also in .htaccess file as php_flag register_globals on

but still global variable is off

please tell me whether this function is available for PHP version 5.2.5 or not????

because i am using PHP version 5.2.5



did you restart the server? you need the changes loaded.

I still advice to use register_globals off.

and of PHP6 register_globals will be dropped.


You can turn register_globals on in all versions of PHP 5, but this is highly discouraged. It enables very bad coding habits and can potentially pose a huge security risk.

If you have no alternative but to turn it on, all you would have to do is change your php.ini to:

register_globals = on

And restart the server, of course.

If for some reason this is giving you trouble, and you absolutely have to have these variables in the global scope, you can use the extract function to simulate this behavior.
For example, this would print a field named "field1" submitted via the POST protocol:

echo $field1;

Note that I DO NOT RECOMMEND THIS, but it is an option if you absolutely have no other choice.


Thanx.You really give me good solutions
Thanks again