1. Home
  2. Archive
  3. Sample Coding
  4. PHP Register_Globals Settings

PHP Register_Globals Settings

Issue

Not sure with settings of PHP Register_Globals and would like to turn ON or turn OFF the register_globals setting for the applications like Joomla and etc.

Symptoms

None

Cause

Lack of knowledge with the Register_Globals Settings

Workaround

For Windows Hosting Environment

Include the following codes in your PHP scripts.

A) To emulate register_globals “on”, include the following code:

<?php
// Emulate register_globals on
if (!ini_get(‘register_globals’)) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
extract($superglobal, EXTR_SKIP);
}
ini_set(‘register_globals’, true);
}
?>

B) To emulate register_globals “off”, include the following code:

<?php
// Emulate register_globals off
if (ini_get(‘register_globals’)) {
$superglobals = array($_SERVER, $_ENV,
$_FILES, $_COOKIE, $_POST, $_GET);
if (isset($_SESSION)) {
array_unshift($superglobals, $_SESSION);
}
foreach ($superglobals as $superglobal) {
foreach ($superglobal as $global => $value) {
unset($GLOBALS[$global]);
}
}
ini_set(‘register_globals’, false);
}
?>

For FreeBSD Hosting Environment

First, you will need to create a .htaccess file in your site’s main directory (or the main directory of your site that contains PHP scripts).

A) To set register_globals “off”, include the following line in your .htaccess file

php_flag register_globals off

B) To set register_globals “on”, include the following line in your .htaccess file

php_flag register_globals on

We recommend that you download the .htaccess file via FTP, open using the file using notepad and include the above command line. Then save it and re-upload to your hosting account via FTP again.

Please ensure you do not enter any other special character other than the above command line to avoid .htaccess file and make your site unreachable.

Additional Information

When register global is On, we can access variable anywhere within the script. If the register_globals=Off in that time we can’t access the variable from another page.

We can turn on register global value using the code for temporarily (in a server where register global value is set to off globally) using these codes.

In new PHP versions such as PHP 5.3.2 it is depreciated. So we can no longer use this in newer features as it a security threat to on this feature. So this code can’t be used in newer versions of PHP.

If you still have the problem above, kindly issue a ticket to Support Team.

Updated on March 14, 2019

Was this article helpful?

Related Articles

Leave a Comment

Need Help?
Submit a ticket to us and let our professional team assists you

Support Billing Sales
Support
Billing
Sales