public function setup() { parent::setup(); Session::start(); $this->app["request"]->setSession(Session::driver()); FieldPresenter::presenter(null); }
public function setup() { parent::setup(); Session::start(); $this->app["request"]->setSession(Session::driver()); $this->presenter = function ($attrs) { return "{$attrs["field"]->label()} {$attrs["field"]->display()}"; }; }
function forceBack($route = null) { if ($route) { $respsponse = redirect()->route($route)->withInput(); } else { $respsponse = back()->withInput(); } \Session::driver()->save(); $respsponse->send(); exit; }
/** * 销毁当前Session * * @return void */ public function destroy() { $_SESSION = array(); Session::$driver->destroy(); Session::$member = null; Session::$driver = null; Session::$instance = null; }
/** * Create a new session. * * @param array variables to set after creation * @param string Force a specific session_id * @return void */ public function create($vars = NULL, $session_id = NULL) { // Destroy any current sessions $this->destroy(); if (Session::$config['driver'] !== 'native') { // Set driver name $driver = 'Session_' . ucfirst(Session::$config['driver']) . '_Driver'; // Load the driver if (!Kohana::auto_load($driver)) { throw new Kohana_Exception('The :driver: driver for the :library: library could not be found', array(':driver:' => Session::$config['driver'], ':library:' => get_class($this))); } // Initialize the driver Session::$driver = new $driver(); // Validate the driver if (!Session::$driver instanceof Session_Driver) { throw new Kohana_Exception('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => Session::$config['driver'], ':library:' => get_class($this), ':interface:' => 'Session_Driver')); } // Register non-native driver as the session handler session_set_save_handler(array(Session::$driver, 'open'), array(Session::$driver, 'close'), array(Session::$driver, 'read'), array(Session::$driver, 'write'), array(Session::$driver, 'destroy'), array(Session::$driver, 'gc')); } // Validate the session name if (!preg_match('~^(?=.*[a-z])[a-z0-9_]++$~iD', Session::$config['name'])) { throw new Kohana_Exception('The session_name, :session:, is invalid. It must contain only alphanumeric characters and underscores. Also at least one letter must be present.', array(':session:' => Session::$config['name'])); } // Name the session, this will also be the name of the cookie session_name(Session::$config['name']); // Set the session cookie parameters session_set_cookie_params(Session::$config['expiration'], Kohana::config('cookie.path'), Kohana::config('cookie.domain'), Kohana::config('cookie.secure'), Kohana::config('cookie.httponly')); $cookie = cookie::get(Session::$config['name']); if ($session_id === NULL) { // Reopen session from signed cookie value. $session_id = $cookie; } // Reopen an existing session if supplied if (!is_null($session_id)) { session_id($session_id); } // Start the session! session_start(); // Put session_id in the session variable $_SESSION['session_id'] = session_id(); // Set defaults if (!isset($_SESSION['_kf_flash_'])) { $_SESSION['total_hits'] = 0; $_SESSION['_kf_flash_'] = array(); $_SESSION['user_agent'] = request::user_agent(); $_SESSION['ip_address'] = $this->input->ip_address(); } // Set up flash variables Session::$flash =& $_SESSION['_kf_flash_']; // Increase total hits $_SESSION['total_hits'] += 1; // Validate data only on hits after one if ($_SESSION['total_hits'] > 1) { // Validate the session foreach (Session::$config['validate'] as $valid) { switch ($valid) { // Check user agent for consistency case 'user_agent': if ($_SESSION[$valid] !== request::user_agent()) { return $this->create(); } break; // Check ip address for consistency // Check ip address for consistency case 'ip_address': if ($_SESSION[$valid] !== $this->input->{$valid}()) { return $this->create(); } break; // Check expiration time to prevent users from manually modifying it // Check expiration time to prevent users from manually modifying it case 'expiration': if (time() - $_SESSION['last_activity'] > ini_get('session.gc_maxlifetime')) { return $this->create(); } break; } } } // Expire flash keys $this->expire_flash(); // Update last activity $_SESSION['last_activity'] = time(); // Set the new data Session::set($vars); }
/** * Create a new session. * * @param array variables to set after creation * @return void */ public function create($vars = NULL) { // Destroy any current sessions $this->destroy(); if (Session::$config['driver'] !== 'native') { // Set driver name $driver = 'Session_' . ucfirst(Session::$config['driver']) . '_Driver'; // Load the driver if (!Kohana::auto_load($driver)) { throw new Kohana_Exception('core.driver_not_found', Session::$config['driver'], get_class($this)); } // Initialize the driver Session::$driver = new $driver(); // Validate the driver if (!Session::$driver instanceof Session_Driver) { throw new Kohana_Exception('core.driver_implements', Session::$config['driver'], get_class($this), 'Session_Driver'); } // Register non-native driver as the session handler session_set_save_handler(array(Session::$driver, 'open'), array(Session::$driver, 'close'), array(Session::$driver, 'read'), array(Session::$driver, 'write'), array(Session::$driver, 'destroy'), array(Session::$driver, 'gc')); } // Validate the session name if (!preg_match('~^(?=.*[a-z])[a-z0-9_]++$~iD', Session::$config['name'])) { throw new Kohana_Exception('session.invalid_session_name', Session::$config['name']); } // Name the session, this will also be the name of the cookie session_name(Session::$config['name']); // Set the session cookie parameters session_set_cookie_params(Session::$config['expiration'], Kohana::config('cookie.path'), Kohana::config('cookie.domain'), Kohana::config('cookie.secure'), Kohana::config('cookie.httponly')); // Start the session! session_start(); // Put session_id in the session variable $_SESSION['session_id'] = session_id(); // Set defaults if (!isset($_SESSION['_kf_flash_'])) { $_SESSION['total_hits'] = 0; $_SESSION['_kf_flash_'] = array(); $_SESSION['user_agent'] = Kohana::$user_agent; $_SESSION['ip_address'] = $this->input->ip_address(); } // Set up flash variables Session::$flash =& $_SESSION['_kf_flash_']; // Increase total hits $_SESSION['total_hits'] += 1; // Validate data only on hits after one if ($_SESSION['total_hits'] > 1) { // Validate the session foreach (Session::$config['validate'] as $valid) { switch ($valid) { // Check user agent for consistency case 'user_agent': if ($_SESSION[$valid] !== Kohana::$user_agent) { return $this->create(); } break; // Check ip address for consistency // Check ip address for consistency // Check ip address for consistency // Check ip address for consistency case 'ip_address': if ($_SESSION[$valid] !== $this->input->{$valid}()) { return $this->create(); } break; // Check expiration time to prevent users from manually modifying it // Check expiration time to prevent users from manually modifying it // Check expiration time to prevent users from manually modifying it // Check expiration time to prevent users from manually modifying it case 'expiration': if (time() - $_SESSION['last_activity'] > ini_get('session.gc_maxlifetime')) { return $this->create(); } break; } } } // Expire flash keys $this->expire_flash(); // Update last activity $_SESSION['last_activity'] = time(); // Set the new data Session::set($vars); }
/** * Create a new session. * * @return void */ public function create() { // Validate the session name if (!preg_match('~^(?=.*[a-z])[a-z0-9_]++$~iD', self::$config['name'])) { throw new KoException('The session_name, :session:, is invalid. It must contain only alphanumeric characters and underscores. Also at least one letter must be present.', array(':session:' => self::$config['name'])); } // Destroy any current sessions $this->destroy(); if (self::$config['driver'] !== 'native') { $driver = 'Session_' . ucfirst(self::$config['driver']); if (!Ko::autoload($driver)) { throw new KoException('The :driver: driver for the :library: library could not be found', array(':driver:' => self::$config['driver'], ':library:' => get_class($this))); } self::$driver = new $driver(); if (!self::$driver instanceof Session_Driver) { throw new KoException('The :driver: driver for the :library: library must implement the :interface: interface', array(':driver:' => self::$config['driver'], ':library:' => get_class($this), ':interface:' => 'Session_Driver')); } session_set_save_handler(array(self::$driver, 'open'), array(self::$driver, 'close'), array(self::$driver, 'read'), array(self::$driver, 'write'), array(self::$driver, 'destroy'), array(self::$driver, 'gc')); } // Name the session, this will also be the name of the cookie session_name(self::$config['name']); // Set the session cookie parameters // session_set_cookie_params(self::$config['lifetime']); // Start the session! session_start(); // Put session_id in the session variable $_SESSION['session_id'] = session_id(); // Update last activity $_SESSION['last_activity'] = time(); }