$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 
$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->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.124

Twitter updates

  • New post: In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124— More
    11 January 2019
  • New ProcessWire main site rebuild ready for preview— More
    4 January 2019
  • Happy Holidays! This latest master version of ProcessWire contains hundreds of new additions, fixes, optimizations and more. This post covers all the highlights— More
    21 December 2018

Latest news

  • ProcessWire Weekly #245
    In the 245th issue of ProcessWire Weekly we're going to focus on some new documentation additions made just this week, cover a couple of new third party modules from Bernhard Baumrock, and introduce a magnificent new travel website called Uncover Colombia. Read on!
    Weekly.pw / 19 January 2019
  • ProcessWire 3.0.124 and new website launched
    In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124.
    Blog / 11 January 2019
  • Subscribe to weekly ProcessWire news

“ProcessWire is like a breath of fresh air. So powerful yet simple to build with and customise, and web editors love it too.” —Margaret Chatwin, Web developer