Knowledgebase: Samples Coding
PHP Register_Globals Settings
Posted by - NA - on 29 September 2010 03:42 PM
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 any where within the script. if the register_globals=Off in that time we can't access variable from anther 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 this codes.

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

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

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).