2017 © Pedro Peláez
 

library lib-session

Abstract library for handling account sessions and cookies

image

openlss/lib-session

Abstract library for handling account sessions and cookies

  • Thursday, April 18, 2013
  • by nullivex
  • Repository
  • 1 Watchers
  • 1 Stars
  • 113 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 0 % Grown

The README.md

openlss/lib-session

Abstract library for handling account sessions and cookies, (*1)

Usage


//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()); }

Reference

(bool) Session::isLoggedIn()

Returns true when a valid session exists, (*2)

(bool) Session::requireLogin()

Redirects to Url::login() if no session is found, (*3)

(bool) Session::checkLogin()

Checks if a session needed to validate a login exists, (*4)

(bool) Session::get($var=false)

Returns MDA key from the session registry When $var is FALSE the entire registry is returned, (*5)

$staff_id = Session::get('staff_id');

(bool) Session::storeSession($session)

Sets the session registry Returns TRUE on success FALSE on failure, (*6)

(string) Session::getTokenFromSession()

Returns the current session token, (*7)

(void) Session::startSession($token)

Stores the token in an actual PHP session, (*8)

(void) Session::destroySession()

Destroys the session help in PHP, (*9)

(array) Session::fetchByToken($token)

Return a session by token, (*10)

(array) Session::findToken($id,$remote_ip,$user_agent)

  • $id The identifier of the account
  • $remote_ip Remote IP address used for session
  • $user_agent The USER_AGENT field of the remote user Returns a session record

(mixed) Session::tokenCheck($token,$remote_ip,$return_token=false)

  • $token The session token
  • $remote_ip Remote IP of the session starter
  • $return_token When FALSE this function returns BOOL otherwise returns the token

(string) Session::tokenCreate($id,$remote_ip,$user_agent)

  • $id The identifier of the account
  • $remote_ip Remote IP address used for session
  • $user_agent The USER_AGENT field of the remote user Returns the newly created token

(string) Session::tokenDestroy($token)

Destroys the given token and returns that token, (*11)

The Versions

09/04 2013

dev-0.0.x-dev

dev-0.0.x-dev http://openlss.org

Abstract library for handling account sessions and cookies

  Sources   Download

LGPL-3.0+

The Requires

 

authentication sessions cookies