PHP code example of hotarunohikari / dr-sso

1. Go to this page and download the library: Download hotarunohikari/dr-sso library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hotarunohikari / dr-sso example snippets



use dr\sso\SSO;
class Index
{
   function index(){
      SSO::getToken($id); //获取指定ID的token,不存在则返回false
      SSO::setToken($id, $token); //设置指定ID的token值,如果ID已经有值则不进行赋值操作,设置成功返回true,否则返回false
      SSO::setTokenForce($id, $token); // 强制设置指定ID的token值,设置成功返回true,否则返回false
      SSO::conflict($id, $token); // 检查已有token是否和给定token冲突,若冲突则返回true,否则返回false
      SSO::pullToken($id); //取出指定ID的token并删除,不存在则返回false
      SSO::delToken($id); //删除指定ID的token,删除成功返回true,否则返回false
   }
}

   return [
        'expire'     => 60 * 60 * 120, // token缓存时间
        'sso'        => 'sso',         // 指定redis中存储token的namespace
        'host'       => '127.0.0.1',   // 以下为redis连接相关信息...
        'port'       => 6379,
        'password'   => '',
        'select'     => 0,
        'timeout'    => 0,
        'persistent' => false,
   ];