/** * 设置某个Cookie值 * * @param string $name 要设置的cookie的名称 * @param mixed $value 要设置的值 * @param int $expire 过期时间 * @param string $path path * @param string $domain domain * * @return void */ public static function set($name, $value, $expire = 0, $path = '', $domain = '') { empty($expire) && ($expire = Config::get('cookie_expire')); empty($path) && ($path = Config::get('cookie_path')); empty($domain) && ($domain = Config::get('cookie_domain')); $expire = empty($expire) ? 0 : Cml::$nowTime + $expire; $value = Encry::encrypt($value); setcookie(Config::get('cookie_prefix') . $name, $value, $expire, $path, $domain); $_COOKIE[Config::get('cookie_prefix') . $name] = $value; }
/** * 保存当前登录用户的信息 * * @param int $uid 用户id * @param bool $sso 是否为单点登录,即踢除其它登录用户 */ public static function setLoginStatus($uid, $sso = true) { $user = ['uid' => $uid, 'expire' => Cml::$nowTime + 3600, 'ssosign' => $sso ? (string) Cml::$nowMicroTime : self::$ssoSign]; //Cookie::set本身有一重加密 这里再加一重 $sso && Model::getInstance()->cache()->set("SSOSingleSignOn{$uid}", (string) Cml::$nowMicroTime); Cookie::set(Config::get('userauthid'), Encry::encrypt(json_encode($user, JSON_UNESCAPED_UNICODE), self::$encryptKey), 0); }
/** * 设置用户登录Cookie * * @param int $uid 用户id */ public static function setLoginStatus($uid) { $user = array('uid' => $uid, 'expire' => Cml::$nowTime + 3600, 'ssosign' => (string) Cml::$nowMicroTime); //Cookie::set本身有一重加密 这里再加一重 Model::getInstance()->cache()->set("SSOSingleSignOn{$uid}", (string) Cml::$nowMicroTime); Cookie::set(Config::get('userauthid'), Encry::encrypt(json_encode($user, PHP_VERSION >= '5.4.0' ? JSON_UNESCAPED_UNICODE : 0), self::$encryptKey), 0); }