Yii2-Session超时设置无效问题处理

        $lifeTime = 5;  
        //因修改了SESSION_ID,设置过期时间必须指定session_name

        //session_set_cookie_params($lifeTime, '/');   //默认session name:PHPSESSIONID

        
        //session_start();        
        //setcookie(session_name(), session_id(), time() + $lifeTime, '/');   //推荐使用,必须在session_start() 之后运行
        
        /* if(!isset($_SESSION['signup_sms'])) {
            $_SESSION['signup_sms'] = 'wccc1';
            echo 'set session. ';
        } */
        
        /* 无效,why?  不能自动识别修改过的PHPSESSIONID?
        Yii::$app->session->setCookieParams([
                'lifetime' => $lifeTime,
                'path' => '/',
            ]
        ); */
        
        //Cannot use isset() on the result of an expression (use "null !== expression" instead)
        if (null == Yii::$app->session->get('signup_sms')){
            Yii::$app->session->set('signup_sms', 'wccc2');            
            echo 'set session. ';
        }
        setcookie(session_name(), session_id(), time() + $lifeTime, '/');
        print_r(Yii::$app->session->get('signup_sms').'
');
        //Yii::$app->session->removeAll();
        //Yii::$app->session->close();
        exit();



你可能感兴趣的:(Yii2,PHP)