/** * Begins the session. */ public static function start() { session_start(); if (isset($_SESSION[self::$name . '_SID'])) { self::$sid = $_SESSION[self::$name . '_SID']; self::$data = $_SESSION[self::$name . '_DATA']; } else { self::$sid = md5(time()); self::$data = array('lang' => Lang::current(), 'uid' => 0); $_SESSION[self::$name . '_SID'] = self::$sid; $_SESSION[self::$name . '_DATA'] = self::$data; } Lang::load(self::_('lang')); if (self::$data['uid']) { self::$logged = true; } }
static function destroy($id) { if (!self::$started) { return; } self::$started = false; session_unset(); //frees the variables (like $_SESSION) self::$data->delete(); self::$data = null; Cookie::remove('sessionId'); Cookie::remove('sessionKey'); }
public function update_session($id, $val) { $session = $this->fetch_session($id); $now = time(); if (empty($session)) { $session = new Session(); $session->session_id = $id; $session->session_kind = 'CO'; } $session->data($val); $session->session_start = $now; $session->save(); return true; }
/** * Destroy the current session (logout). */ public static function destroy() { if (self::isLoggedIn()) { apc_delete(Cache::PREFIX . 'user_' . self::$data['username']); } self::$data = array(); if (ini_get("session.use_cookies")) { $params = session_get_cookie_params(); setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]); } session_destroy(); }
public static function start() { if (isset($_SESSION["user"])) { self::$data = unserialize($_SESSION["user"]); } self::$instance = new Session(); }
/** * Function: read * Reads their session from the database. * * Parameters: * $id - Session ID. */ static function read($id) { self::$data = SQL::current()->select("sessions", "data", array("id" => $id), "id")->fetchColumn(); return fallback(self::$data, ""); }
public function testOne() { $session = new Session(); $session->user = "******"; $this->assertEquals(array("user" => "admin"), $session->data()); }