Maintains sessions in ProcessWire, authentication, persistent variables, notices and redirects.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Session class also inherits all the methods and properties of: Wire.

Common / Authentication / Notices / For hooks


Name Return Summary  
$session->CSRF() SessionCSRF Return an instance of ProcessWire’s CSRF object, which provides an API for cross site request forgery protection.
Can also be used as property: $session->CSRF
$session->get($key) mixed Get a session variable
$session->getAll() array Get all session variables in an associative array
$session->getFor($ns, string $key) mixed Get a session variable within a given namespace
$session->getHistory() array Get the session history (if enabled)
$session->getIP() string or int Get the IP address of the current user
$session->getIterator() ArrayObject Allow iteration of session variables
$session->hasCookie() bool Are session cookie(s) present?
$session->redirect(string $url) (nothing) Redirect this session to another URL.
$session->remove($key) $this Unset a session variable
$session->removeFor($ns, string $key) $this Unset a session variable within a namespace
$session->set($key, $value) $this Set a session variable
$session->setFor($ns, string $key, mixed $value) $this Set a session variable within a given namespace


Name Return Summary  
$session->forceLogin($user) User or null Login a user without requiring a password
$session->login($name, string $pass) User or null Login a user with the given name and password
$session->logout() $this Logout the current user, and clear all session variables


Name Return Summary  
$session->error(string $text) $this Queue an error to appear on the next pageview
$session->message(string $text) $this Queue a message to appear on the next pageview
$session->removeNotices() (nothing) Remove queued notices
$session->warning(string $text) $this Queue a warning to appear the next pageview

For hooks

This methods are only useful for hooking and should not be called directly.

Name Return Summary  
$session->allowLogin(string $name) bool Allow the user $name to login? Provided for use by hooks.
$session->authenticate(User $user, string $pass) bool Return true or false whether the user authenticated with the supplied password
$session->init() (nothing) Start the session
$session->isValidSession(int $userID) bool Checks if the session is valid based on a challenge cookie and fingerprint
$session->loginFailure(string $name, string $reason) (nothing) Login failure method for hooks
$session->loginSuccess(User $user) (nothing) Login success method for hooks
$session->logoutSuccess(User $user) (nothing) Logout success method for hooks

Additional methods and properties

In addition to the methods and properties above, Session also inherits the methods and properties of these classes: