$session
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.
Redirects
| Name | Return | Summary | |
|---|---|---|---|
$session->location() $session->location(string $url) $session->location(string $url, int $status = 302) | None | Perform a temporary redirect | |
$session->redirect() $session->redirect(string $url) $session->redirect(string $url, $status = 301) | None | Redirect this session to another URL. |
Get
| Name | Return | Summary | |
|---|---|---|---|
$session->get() $session->get($key) $session->get($key, string $_key = null) | mixed | Get a session variable | |
$session->getAll() $session->getAll() $session->getAll($ns = null) | array | Get all session variables in an associative array | |
$session->getAllFor() $session->getAllFor($ns) $session->getAllFor($ns) | array | Get all session variables for given namespace and return associative array | |
$session->getFor() $session->getFor($ns, string $key) $session->getFor($ns, string $key) | mixed | Get a session variable within a given namespace | |
$session->getVal() $session->getVal(string $key) $session->getVal(string $key, mixed $val = null) | mixed | Get a session variable or return $val argument if session value not present | |
$session->getValFor() $session->getValFor($ns, string $key) $session->getValFor($ns, string $key, mixed $val = null) | mixed | Get a session variable or return $val argument if session value not present |
Set
| Name | Return | Summary | |
|---|---|---|---|
$session->set() $session->set($key, $value) $session->set($key, $value, mixed $_value = null) | $this | Set a session variable | |
$session->setFor() $session->setFor($ns, string $key, mixed $value) $session->setFor($ns, string $key, mixed $value) | $this | Set a session variable within a given namespace |
Remove
| Name | Return | Summary | |
|---|---|---|---|
$session->remove() $session->remove($key) $session->remove($key, $_key = null) | $this | Unset a session variable | |
$session->removeAllFor() $session->removeAllFor($ns) $session->removeAllFor($ns) | $this | Remove all session variables in given namespace | |
$session->removeFor() $session->removeFor($ns, string $key) $session->removeFor($ns, string $key) | $this | Unset a session variable within a namespace |
Info
| Name | Return | Summary | |
|---|---|---|---|
$session->getIP() $session->getIP() $session->getIP(bool $int = false, $useClient = false) | string int | Get the IP address of the current user | |
$session->hasCookie() $session->hasCookie() $session->hasCookie(bool $checkLogin = false) | bool | Are session cookie(s) present? | |
$session->hasLoginCookie() $session->hasLoginCookie() $session->hasLoginCookie() | bool | Is a session login cookie present? |
Notices
| Name | Return | Summary | |
|---|---|---|---|
$session->error() $session->error(string $text) $session->error(string $text, int $flags = 0) | $this | Queue an error to appear on the next pageview | |
$session->message() $session->message(string $text) $session->message(string $text, int $flags = 0) | $this | Queue a message to appear on the next pageview | |
$session->removeNotices() $session->removeNotices() $session->removeNotices() | None | Remove queued notices | |
$session->warning() $session->warning(string $text) $session->warning(string $text, int $flags = 0) | $this | Queue a warning to appear the next pageview |
Authentication
| Name | Return | Summary | |
|---|---|---|---|
$session->forceLogin() $session->forceLogin($user) $session->forceLogin($user) | User null | Login a user without requiring a password | |
$session->login() $session->login($name, string $pass) $session->login($name, string $pass, bool $force = false) | User null | Login a user with the given name and password | |
$session->logout() $session->logout() $session->logout(bool $startNew = true) | $this | Logout the current user, and clear all session variables |
Advanced
| Name | Return | Summary | |
|---|---|---|---|
$session->CSRF() $session->CSRF() $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->getHistory() $session->getHistory() $session->getHistory() | array | Get the session history (if enabled) |
For hooks
These methods are only useful for hooking and should not be called directly.
Common
| Name | Return | Summary | |
|---|---|---|---|
$session->close() $session->close() $session->close() | None | Manually close the session, before program execution is done |
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.252