手册……
Session 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.
Session 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.
session_start();
if(!isset($_SESSION['count']))
$_SESSION['count'] = 0;
echo $_SESSION['count']++;
?>
执行后刷新看看
$_SESSION['变量名'] = 变量值;输出一个已存在session 变量值
echo $_SESSION['变量名'];<?php
session_start();
if(!$_SESSION['testS']){
$_SESSION['testS'] = "测试";
echo "请刷新";
}else{
echo $_SESSION['testS'];
}
?>