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

Show “$session”             Show Arguments        

Common

NameReturnSummary 
$session->CSRF()
SessionCSRFReturn 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)
mixedGet a session variable
$session->getAll()
arrayGet all session variables in an associative array
$session->getFor($ns, string $key)
mixedGet a session variable within a given namespace
$session->getHistory()
arrayGet the session history (if enabled)
$session->getIP()
string or intGet the IP address of the current user
$session->getIterator()
ArrayObjectAllow iteration of session variables
$session->hasCookie()
boolAre session cookie(s) present?
$session->redirect(string $url)
(nothing)Redirect this session to another URL.
$session->remove($key)
$thisUnset a session variable
$session->removeFor($ns, string $key)
$thisUnset a session variable within a namespace
$session->set($key, $value)
$thisSet a session variable
$session->setFor($ns, string $key, mixed $value)
$thisSet a session variable within a given namespace

Authentication

NameReturnSummary 
$session->forceLogin($user)
User or nullLogin a user without requiring a password
$session->login($name, string $pass)
User or nullLogin a user with the given name and password
$session->logout()
$thisLogout the current user, and clear all session variables

Notices

NameReturnSummary 
$session->error(string $text)
$thisQueue an error to appear on the next pageview
$session->message(string $text)
$thisQueue a message to appear on the next pageview
$session->removeNotices()
(nothing)Remove queued notices
$session->warning(string $text)
$thisQueue a warning to appear the next pageview

For hooks

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

NameReturnSummary 
$session->allowLogin(string $name)
boolAllow the user $name to login? Provided for use by hooks.
$session->authenticate(User $user, string $pass)
boolReturn true or false whether the user authenticated with the supplied password
$session->init()
(nothing)Start the session
$session->isValidSession(int $userID)
boolChecks 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:

API reference based on ProcessWire core version 3.0.61