PHP 5 and global variables

Posted on 2008-11-13
Last Modified: 2012-05-05
Since register_globals is turned off by default in PHP 5, I am curious if the following line would not work:
global $_POST
Will the code above work in PHP 5 with register_globals turned off?
Question by:msosno
    LVL 7

    Accepted Solution

    Hi, from the site:

    HTTP POST variables: $_POST
    Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.
    An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

    This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

    $HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that $HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

    If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
    LVL 36

    Assisted Solution

    by:Loganathan Natarajan
    $_POST is a global variable ... you need not again to define as global variable... do you have any problem in accessing the variable?
    LVL 34

    Assisted Solution

    by:Beverley Portlock
    Just to be clear, there is a big difference between the "global" keyword and register_globals - they are NOTHING to do with each other.

    Register_globals *creates* variables automatically from the URL query string. It is considered to be the biggest single security flaw in PHP which is why it is off by default. See

    The "global" keyword makes variables defined outside a function visible inside a function. It is not considered good programming practice to use "global". See

    Finally there are special arrays that are defined as SUPER GLOBALS that are available in all contexts. These are things like $_POST, $_GET, $_SERVER, $_SESSION and $_COOKIE. See

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now