+ -
当前位置:首页 → 问答吧 → 关于SESSION失效问题

关于SESSION失效问题

时间:2007-11-04

来源:互联网

文件abc.php
复制PHP内容到剪贴板
PHP代码:

<?php
function abc()
{  
if (!isset($_SESSION)) {
     session_start();
}
   session_destroy();
   session_register('abc'); 
   $_SESSION["abc"] = "123123";
   return;
}
?>

文件:b.php
复制PHP内容到剪贴板
PHP代码:

<?php
include('./abc.php');  
   abc();
   echo $_SESSION['abc'];
?>

编译前可以正常输出:SESSION值:123123
经过编译后SESSION就失效。

不知道是PHP编译工具的原因还是zend的原因?

[ 本帖最后由 adleyliu 于 2007-11-4 11:31 编辑 ]

作者: adleyliu   发布时间: 2007-11-04

是否需要在程序最前面添加 session_start(); ?

作者: diekiss   发布时间: 2007-11-04

复制内容到剪贴板
代码:
if (!isset($_SESSION)) {
     session_start();
}
以上代码纯粹多于。应该在程序最前面添加 session_start();
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 a superglobal. (Note that $HTTP_SESSION_VARS and $_SESSION 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 $_SESSION and $HTTP_SESSION_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not superglobals.

作者: diekiss   发布时间: 2007-11-04

热门下载

更多