$_SESSION

$HTTP_SESSION_VARS [deprecated]

(PHP 4 >= 4.1.0, PHP 5)

$_SESSION -- $HTTP_SESSION_VARS [deprecated]Session variables

Description

An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.

$HTTP_SESSION_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_SESSION_VARS and $_SESSION are different variables and that PHP handles them as such)

Changelog

Version Description
4.1.0 Introduced $_SESSION that deprecated $HTTP_SESSION_VARS.

Notes

Note:

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. There is no need to do global $variable; to access it within functions or methods.

See Also

Коментарии

You may have trouble if you use '|' in the key:

$_SESSION["foo|bar"] = "fuzzy";

This does not work for me. I think it's because the serialisation of session object is using this char so the server reset your session when it cannot read it.

To make it work I replaced '|' by '_'.
2008-08-01 19:16:05
http://php5.kiev.ua/manual/ru/reserved.variables.session.html
Автор:
Please note that if you have register_globals to On, global variables associated to $_SESSION variables are references, so this may lead to some weird situations.

<?php

session_start
();

$_SESSION['test'] = 42;
$test 43;
echo 
$_SESSION['test'];

?>

Load the page, OK it displays 42, reload the page... it displays 43.

The solution is to do this after each time you do a session_start() :

<?php

if (ini_get('register_globals'))
{
    foreach (
$_SESSION as $key=>$value)
    {
        if (isset(
$GLOBALS[$key]))
            unset(
$GLOBALS[$key]);
    }
}

?>
2008-08-31 17:43:37
http://php5.kiev.ua/manual/ru/reserved.variables.session.html
I was having troubles with session variables working in some environments and being seriously flaky in others. I was using $_SESSION as an array. It works properly when I used $_SESSION as pointers to arrays. As an example the following code works in some environments and not others.

<?php
//Trouble if I treate $form_convert and $_SESSION['form_convert'] as unrelated items
$form_convert=array();
if (isset(
$_SESSION['form_convert'])){
       
$form_convert=$_SESSION['form_convert'];
    }
}
?>
The following works well. 
<?php
if (isset($_SESSION['form_convert'])){
   
$form_convert $_SESSION['form_convert'];
}else{
   
$form_convert = array();
   
$_SESSION['form_convert']=$form_convert;
}
?>
2009-07-04 21:47:26
http://php5.kiev.ua/manual/ru/reserved.variables.session.html
Be carefull with $_SESSION array elements when you have the same name as a normal global.

The following example leads to unpredictable behaviour of the $wppa array elements, some are updated by normal code, some not, it is totally unpredictable what happens.

<?php
global $wppa;
$wppa = array( 'elm1' => 'value1''elm2' => 'value2', ....etc...);

if ( ! 
session_id() ) @ session_start();
if ( ! isset(
$_SESSION['wppa']) $_SESSION['wppa'] = array();

if ( ! isset(
$_SESSION['wppa']['album']) ) $_SESSION['wppa']['album'] = array();
$_SESSION['wppa']['album'][1234] = 1;

$wppa['elm1'] = 'newvalue1';

print_r($_SESSION); 
?>
This will most likely display Array ( [wppa] => Array ( [album] => Array ( [1234] => 1 ) [elm1] => 'newvalue1' [elm2] => 'value2' ... etc ...
But setting $wppa['elm1'] to another value or referring to it gives unpredictable results, maybe 'value1', or 'newvalue1'. 

The most strange behaviour is that not all elements of $wppa[xx] show up as $_SESSION['wppa'][xx].
2013-08-31 14:51:39
http://php5.kiev.ua/manual/ru/reserved.variables.session.html
Автор:
Creating New Session
==========================
<?php 
session_start
();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
?>
Getting Session
==========================
<?php 
session_start
();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
/*session created*/
echo $_SESSION["newsession"];
/*session was getting*/
?>
Updating Session
==========================
<?php 
session_start
();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
/*it is my new session*/
$_SESSION["newsession"]=$updatedvalue;
/*session updated*/
?>
Deleting Session
==========================
<?php 
session_start
();
/*session is started if you don't write this line can't use $_Session  global variable*/
$_SESSION["newsession"]=$value;
unset(
$_SESSION["newsession"]);
/*session deleted. if you try using this you've got an error*/
?>
2015-03-09 19:04:49
http://php5.kiev.ua/manual/ru/reserved.variables.session.html
I would be wary to use PHP Sessions for application-critical tasks. So far, I have had very troubling experiences with random loss of session data, as described in these bug reports:

https://bugs.php.net/bug.php?id=19022
https://bugs.php.net/bug.php?id=19029
https://bugs.php.net/bug.php?id=70584
2019-01-25 13:56:35
http://php5.kiev.ua/manual/ru/reserved.variables.session.html

    Поддержать сайт на родительском проекте КГБ