http://www.php.net/manual/en/ref.session.phpUse of $_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended for security and code readablity. With $_SESSION or $HTTP_SESSION_VARS, there is no need to use session_register()/session_unregister()/session_is_registered() functions. Users can access session variable like a normal variable. Caution If you are using $HTTP_SESSION_VARS/$_SESSION and disable register_globals, do not use session_register(), session_is_registered() and session_unregister(). If you enable register_globals, session_unregister() should be used since session variables are registered as global variables when session data is deserialized. Disabling register_globals is recommended for both security and performance reason.
// 静态变数的例子
function myfunc() {
static $mystr;
$mystr.="哈";
echo $mystr."<br>\n";
}
myfunc(); // 哈
myfunc(); // 哈哈
myfunc(); // 哈哈哈
?>
函式在执行时所产生的变数,在函式结束时就消失了,有时因为程式的需要,函式在回圈中,当不希望变数在每次执行完函式就消失的话,静态变数 (static variable) 就派上用场了。上例中,使用 $mystr 变数之前,先在变数前面加上 static,即表示变数 $mystr 是静态变数,当每次执行 myfunc() 函式时,$mystr 的值会一直增加,每执行一次就多一个哈字。若将 static 的静态变数宣告拿掉,就没办法累加哈字了。<?php
// 不是静态变数的例子 (错误的)
function myfunc() {
$mystr.="哈";
echo $mystr."<br>\n";
}
myfunc(); // 哈
myfunc(); // 哈
myfunc(); // 哈
?>那么,你现在知道把register_globals=off关掉,会发生什么情况了吧。:)
是php的预定义变量,也是全域变量
是php的预定义变量
属于globals
$ttt当然不变,但是我程序中已经赋值了$ttt = $_SESSION['ttt'];
并且页面刷新一次,就重新注册新的session "ttt"to anybody1(随便编一个) :
你说的我都明白,那么我的测试程序应该如何写?
<?php
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
}
echo $_SESSION['count'];
?>
刷新页面,是否显示递增?
我自己测试结果一直显示0
我用你的第一个程序,刷了n边同样,数值没有递增~~
why?
请问那一个地方?
If you are using $HTTP_SESSION_VARS/$_SESSION and disable register_globals, do not use session_register(), session_is_registered() and session_unregister(). If you enable register_globals, session_unregister() should be used since session variables are registered as global variables when session data is deserialized. Disabling register_globals is recommended for both security and performance reason.
手册中没有说不需要使用session_start(),但是根据给出的例子,应该是可以不需要session_start()函数和其他的session_*()函数 darkwing() ,看清楚了么?需要我翻译么?