why ini_set('session.gc_maxlifetime',60) doesn't work?

流过昼夜 提交于 2019-12-13 17:07:22

问题


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/>');
    ?>

回答1:


Because garbage collector starts (if starts) before session

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




回答2:


The session garbage collector will fire as part of session_start(). Since you're changing the setting AFTER you start a session, you're too late to change the settings.



来源:https://stackoverflow.com/questions/12032306/why-ini-setsession-gc-maxlifetime-60-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!