Hello,
I would like to get some advices to know what is the difference, and then what's the better to use, between: $HTTP_SESSION_VARS and $_SESSION.
I need to access global variables from functions and therefor I am obliged to specify
global $HTTP_SESSION_VARS;
which is not the case if I use $_SESSION.
I am not sure to understand what there is two ways to get the same result.
$HTTP_SESSION_VARS or $_SESSION ?
Moderator: General Moderators
It is dependent on which version of php you are using.
MarkSession variables: $_SESSION
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_SESSION_VARS.
An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.
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 $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
$HTTP_SESSION_VARS contains the same information, but is not an autoglobal.
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 $_SESSION and $HTTP_SESSION_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
$HTTP_SESSION_VARS still available but deprecated
"$_SESSION
Variables which are currently registered to a script's session. Analogous to the old $HTTP_SESSION_VARS array (which is still available, but deprecated)."
Thanks, I didn't notice that before.
Variables which are currently registered to a script's session. Analogous to the old $HTTP_SESSION_VARS array (which is still available, but deprecated)."
Thanks, I didn't notice that before.