为什么ini_set('session.gc_maxlifetime',60)不起作用? [英] why ini_set('session.gc_maxlifetime',60) doesn't work?

查看:215
本文介绍了为什么ini_set('session.gc_maxlifetime',60)不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话的默认过期时间是1440,我希望将这个时间减少到60秒,但是当我使用 ini_set('session.gc_maxlifetime','60')在它的第一页工作,但它不工作在其他页面,
请告诉我什么是我的错?

the default expire time of session is 1440,i want to reduce this time to 60 second,but when i use ini_set('session.gc_maxlifetime','60') in the first page it work,but it doesn't work in an other page, please tell me what is my wrong?

    ----------index.php-----------
    <?php
    ini_set('session.gc_maxlifetime','60');
    session_start();       

    $_SESSION['id']='123';

    print('<br/><a href="link.php">link<a/>');
    ?>


    ----------link.php----------
    <?php
    session_start();

    if(isset($_SESSION['id'])){
        ini_set('session.gc_maxlifetime',60);
    }else{
        header('Location:index.php?ERROR');
    }

    print('<br/><a href="link.php?1">menu<a/>');
    ?>


推荐答案

因为垃圾收集器启动之前会话

Because garbage collector starts (if starts) before session

因此,在 ini_set('session.gc_maxlifetime',60); 之后设置 session_start()不会变化

So setting ini_set('session.gc_maxlifetime',60); after session_start() changes nothing

这篇关于为什么ini_set('session.gc_maxlifetime',60)不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆