$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?        

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 intGet the IP address of the current user (IPv4) 
$session->getIterator()
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 
$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->removeAllFor($ns)
$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 

Authentication

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

Twitter updates

  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019
  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019
  • Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment— More
    2 August 2019

Latest news

  • ProcessWire Weekly #279
    This week in the 279th issue of ProcessWire Weekly we're going to introduce some of the latest third party modules out there, and highlight a brand new site of the week. Read on!
    Weekly.pw / 14 September 2019
  • ProcessWire 3.0.140 and FormBuilder v40
    This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140.
    Blog / 6 September 2019
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK