PHP,JSP,ASP.NET都是一样的呀.任何技术都是一样.有一个有效期.
但具体的时间是不一样的.

解决方案 »

  1.   

    差不多.
    保存一天:
    session_start(); 
    $lifeTime = 24 * 3600; 
    setcookie(session_name(), session_id(), time() + $lifeTime, "/");
      

  2.   

    查看php.ini里面的session.gc_maxlifetime,和cookie无关,cookie的时间只决定这个session_id的存在时间
      

  3.   

    PHP.INI的session设置:
    [Session] 
    session.save_handler = files ; handler used to store/retrieve data(用什么保存session变量,默认情况下用文件) 
    session.save_path = c:/temp ; argument passed to save_handler(保存session变量的目录,在linux/unix下为/tmp,在win下设为你的目录) 
    ; in the case of files, this is the 
    ; path where data files are stored 
    session.use_cookies = 1 ; whether to use cookies(是否使用cookies,当然,在win下别无选择) 
    session.name = PHPSESSID 
    ; name of the session(默认session使用的cookies名,建议不要改动) 
    ; is used as cookie name 
    session.auto_start = 0 ; initialize session on request startup(是否自动启用session,当为1时,在每页中就可以不必调用session_start()函数了) 
    session.cookie_lifetime = 0 ; lifetime in seconds of cookie(设定 cookie 送到浏览器后的保存时间,单位为秒。缺省值为 0,表示直到浏览器关闭。) 
    ; or if 0, until browser is restarted 
    session.cookie_path = / ; the path the cookie is valid for(cookie)(cookies有效路径) 
    session.cookie_domain = ; the domain the cookie is valid for(cookies有效域名) 
    session.serialize_handler = php ; handler used to serialize data(定义序列化数据的标识,本功能只有 WDDX 模块或 PHP 内部使用。缺省值为 php) 
    ; php is the standard serializer of PHP 
    session.gc_probability = 1 ; percentual probability that the (设定每次临时文件开始处理 (gc, garbage collection) 处理概率。缺省值为 1。 ) 
    ; garbage collection process is started 
    ; on every session initialization 
    session.gc_maxlifetime = 1440 ; after this number of seconds, stored(设定保存session的临时文件被清除前的存活秒数) 
    ; data will be seen as garbage and 
    ; cleaned up by the gc process 
    session.referer_check = ; check HTTP Referer to invalidate (决定参照到客户端的 Session 代码是否要删除。有时在安全或其它考虑时,会设定不删除。缺省值为 0。) 
    ; externally stored URLs containing ids 
    session.entropy_length = 0 ; how many bytes to read from the file(设定 session 从高熵值资源读取的位数。缺省值为 0.) 
    session.entropy_file = ; specified here to create the session id(设定 session 代码建立时,使用外部高熵值资源或文件来建立,例如 UNIX 系统上的 /dev/random 或 /dev/urandom。 ) 
    ; session.entropy_length = 16 
    ; session.entropy_file = /dev/urandom 
    session.cache_limiter = nocache ; set to {nocache,private,public} to (设定session 缓冲限制) 
    ; determine HTTP caching aspects 
    session.cache_expire = 180 ; document expires after n minutes(文档有效期,单位为分钟)这里就有如何设置SESSION的保存时间的设置(一次性设置),也可象楼上那样设置时间(针对每个SESSION分别设置)
      

  4.   

    我写了两个页面来验证:
    页面1:
    <?phpsession_start();
    $_SESSION["admin"] = 1;header("Location: index2.php");?>页面2:
    <?phpsession_start();if (isset($_SESSION["admin"]) && $_SESSION["admin"] === 1) 
    echo "OK";
    else
    echo "expired";?>gc_maxlifetime 我设置成为120是不是过了 120s 后我再刷新 页面2 ,就应该显示 expired 而不是OK
    可实际好像并不是这样,是不是我的理解还是有误?