如何在PHP中包括Authtimeout

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在PHP中包括Authtimeout相关的知识,希望对你有一定的参考价值。

我正在使用REST API phpCodeigniter令牌在jwt中工作,我只想在身份验证中包括超时,这意味着如果用户在1分钟内未进行任何活动,则他应该注销/ accessToken变为null , 我怎样才能做到这一点?这是我的代码,用于检查每个请求的用户身份验证,但是如何添加超时?

private function auths($token,$userType,$usersId)
    
        $users['rec'] = $this->Model_users->checkAuth($token,$userType,$usersId);
        //$users['rec'] getting query result (whether token existing in databse or not )
        if($users['rec']!="")
            
                return;
            
        else
            
                $responseJSON = array("Status" => false,"Result" => "AccessToken not matched");
                header("content-type:application/json");
                $response = json_encode($responseJSON);
                echo $response;
                exit;
            
    
答案
您是否希望整个会话在1分钟后终止(或只是某个会话变量)?

如果是整个会话和所有变量,则可以使用

ini_set('session.gc_maxlifetime', 60); //Set the time in seconds

会话闲置60秒后,会话将超时

以上是关于如何在PHP中包括Authtimeout的主要内容,如果未能解决你的问题,请参考以下文章