$session API variable / Session class

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.

Show $var?             Show args?        


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
mixedGet a session variable 
arrayGet all session variables in an associative array 
arrayGet all session variables for given namespace and return associative array 
$session->getFor($ns, string $key)
mixedGet a session variable within a given namespace 
arrayGet the session history (if enabled) 
string intGet the IP address of the current user 
ArrayObjectAllow iteration of session variables 
$session->getVal(string $key)
mixedGet a session variable or return $val argument if session value not present 
$session->getValFor($ns, string $key)
mixedGet a session variable or return $val argument if session value not present 
boolAre session cookie(s) present? 
boolIs a session login cookie present? 
$session->location(string $url)
(nothing)Perform a temporary (302) redirect 
$session->redirect(string $url)
(nothing)Redirect this session to another URL.
$thisUnset a session variable 
$thisRemove all session variables in given namespace 
$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 


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.185

Twitter updates

  • ProcessWire 3.0.192 (dev branch) contains 11 issue fixes and 5 pull requests, over 20 commits— More
    7 January 2022
  • ProcessWire 3.0.191 core updates: updates to the installer and the profile exporter module— More
    24 December 2021
  • This week ProcessWire went on a diet, trimming the core size from 15.5 MB down to 7.5 MB by moving optional site profiles into their own GitHub repos— More
    17 December 2021

Latest news

  • ProcessWire Weekly #402
    In the 402nd issue of ProcessWire Weekly we'll check out ProcessWire 3.0.193, highlight recent ProcessWire projects and resources, and more. Read on!
    Weekly.pw / 22 January 2022
  • ProcessWire 3.0.190 core updates
    ProcessWire 3.0.190 has 15 commits relative to 3.0.189 and contains a mixture of issue resolutions and feature additions. This post covers them all, in addition to updates for the PageAutosave and ProFields Table modules.
    Blog / 3 December 2021
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits