openlss / lib-session
用于处理账户会话和cookie的抽象库
0.0.10
2013-04-18 02:46 UTC
Requires
- php: >=5.3.2
- openlss/core-boot: ~0.0.1
- openlss/func-bcrypt: ~0.0.1
- openlss/func-gen: ~0.0.1
- openlss/func-mda: ~0.0.1
- openlss/func-mda-glob: ~0.0.1
- openlss/func-ui: ~0.0.1
- openlss/lib-url: ~0.0.1
This package is not auto-updated.
Last update: 2024-09-14 15:18:03 UTC
README
用于处理账户会话和cookie的抽象库
用法
//extending abstract class StaffSession extends \LSS\Session { public static function requireManager(){ if(self::get('is_manager')) return true; throw new Exception('Permission denied'); } public static function init(){ self::$config_name = 'staff'; self::$session_name = 'staff_token'; self::$session_table = 'staff_session'; self::$user_primary_key = 'staff_id'; } } //overrides the parent vars StaffSession::init(); //check for session try { if(StaffSession::checkLogin()){ //register session $token = StaffSession::fetchByToken(StaffSession::getTokenFromSession()); $session = array_merge(Staff::fetch($token['staff_id']),$token); StaffSession::storeSession($session); unset($session,$token); //set tpl globals (if Tpl is available) if(is_callable(array('Tpl','_get'))){ Tpl::_get()->set(array( 'staff_name' => StaffSession::get('name') ,'staff_lastlogin' => date(Config::get('account.date.general_format'),StaffSession::get('last_login')) )); } } else { if(server('REQUEST_URI') != Url::login()) redirect(Url::login()); } } catch(Exception $e){ StaffSession::tokenDestroy(StaffSession::getTokenFromSession()); StaffSession::destroySession(); redirect(Url::login()); }
参考
(bool) Session::isLoggedIn()
如果存在有效的会话,则返回true
(bool) Session::requireLogin()
如果没有找到会话,则重定向到Url::login()
(bool) Session::checkLogin()
检查是否存在用于验证登录的会话
(bool) Session::get($var=false)
从会话注册表中返回MDA键。当$var为FALSE时,返回整个注册表
$staff_id = Session::get('staff_id');
(bool) Session::storeSession($session)
设置会话注册表。成功时返回TRUE,失败时返回FALSE
(string) Session::getTokenFromSession()
返回当前会话令牌
(void) Session::startSession($token)
将令牌存储在实际的PHP会话中
(void) Session::destroySession()
销毁会话(帮助PHP)
(array) Session::fetchByToken($token)
通过令牌返回会话
(array) Session::findToken($id,$remote_ip,$user_agent)
- $id 账户标识符
- $remote_ip 用于会话的远程IP地址
- $user_agent 远程用户的USER_AGENT字段。返回会话记录
(mixed) Session::tokenCheck($token,$remote_ip,$return_token=false)
- $token 会话令牌
- $remote_ip 会话启动者的远程IP
- $return_token 当FALSE时,此函数返回BOOL,否则返回令牌
(string) Session::tokenCreate($id,$remote_ip,$user_agent)
- $id 账户标识符
- $remote_ip 用于会话的远程IP地址
- $user_agent 远程用户的USER_AGENT字段。返回新创建的令牌
(string) Session::tokenDestroy($token)
销毁指定的令牌并返回该令牌