Home > General > How to Change Register Globals Value for Your Website

How to Change Register Globals Value for Your Website

There are some resources that recommend you to set register_globals become Off on your PHP installation in order to keep your website secure. Some of them are:
- Using Register Globals
- How do I deal with register_globals?
We are not talking or discussing about those resources, but the question is: “How do I change this register_globals value become Off anyhow if its directive on my server currently is On, and in the same time I could not change the register_globals directive from the php.ini file?” Well, here is the solution for you.

  1. First of all, create an .htaccess file inside your web root directory (if it does not exist before), and then copy this code to the top section of the file:

    1
    2
    
    # Force Register Globals Off !
    php_flag register_globals off
  2. Make sure that your register_globals setting now is off, by using the following code. Create a new .php file (for example: checkregisterglobals.php) and put this file inside your web root directory.

    1
    2
    3
    4
    5
    6
    7
    8
    
    <?php
      $checkregisterglobals = ini_get('register_globals');
      if($checkregisterglobals == 1){
        echo "Your register_globals is ON";
      } else {
        echo "Your register_globals is OFF";
      }
    ?>

    and then call this file from your browser, for example: http://www.yourdomain.com/checkregisterglobals.php, and it should be return an output as: Your register_globals is OFF.

If you want to change the opposite of that value, then change the code in .htaccess file as follow:

1
2
# Force Register Globals On !
php_flag register_globals on

WARNING: It is strongly not recommended you change or set this register_globals directive become On. You are responsible for the consequence caused by this setting..

  • Share/Bookmark
314 views Print This Post Print This Post

  1. No comments yet.
  1. No trackbacks yet.