static function clr($key) { $a = func_get_args(); if (is_array($key)) { foreach ($key as $k) { session::clr($k); } } elseif (count($a) > 1) { foreach ($a as $k) { session::clr($k); } } else { if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } } }
/** * @brief Suid to another user. * * The aim of this function is to allow the user to become another user, * for testing or administrative purposes. It is similar to the sudo and * su commands in the *nix world. * * A user can only suid ONCE, and is only allowed to switch back to the * previous (original) user by passing NULL as the user record. * * @todo Thorougly test * @param UserRecord $user The user to suid to or null to revert * @return boolean True on success */ static function suid(UserRecord $user = null) { $suid = (array) session::get(User::KEY_USER_SUID, null); if (arr::hasKey($suid, 'issuid') && $user == null) { // Can unsuid $uid = $suid['uid']; session::set(User::KEY_USER_AUTH, $uid); session::clr(User::KEY_USER_SUID); // user::set return true; } elseif ($user) { // Can suid session::set(User::KEY_USER_SUID, array('issuid' => true, 'uid' => user::getActiveUser()->userid, 'suid' => $user->userid)); session::set(User::KEY_USER_AUTH, $user->userid); return true; } else { throw new SecurityException("Invalid suid attempt"); } }
static function initialize() { self::$cookies = $_COOKIE; if (class_exists('session')) { // Grab the cookie jar and set cookies as needed self::$jar = (array) session::get('__cookiejar'); // Add the cookies from the jar to the cookies collection so // we can access them. foreach (self::$jar as $cookie) { self::$cookies[$cookie[0]] = $cookie[1]; } if (!headers_sent()) { foreach (self::$jar as $cookie) { call_user_func_array('setcookie', $cookie); session::clr('__cookiejar'); } // Then empty the jar self::$jar = array(); session::clr('__cookiejar'); } else { throw new BaseException("Cookie jar for delayed cookies loaded but output already started"); } } }
/** * @brief Delete the current viewstate. * * The data will remain in place in the object, so save() can be called * again to create a new state. */ function delete() { if ($this->stateid != null) { session::clr('viewstate_' . $this->stateid); $this->stateid = null; } else { throw new BaseException("Can't delete a non-saved viewstate"); } }