LLMS_Session::init_cookie()
Initialize the session cookie
Description Description
Retrieves and validates the cookie, when there’s a valid cookie it will initialize the object with data from the cookie. Otherwise it sets up and saves a new session and cookie.
Return Return
(void)
Source Source
File: includes/class.llms.session.php
protected function init_cookie() {
$cookie = $this->get_cookie();
$set_cookie = false;
if ( $cookie ) {
$this->id = $cookie[0];
$this->expires = $cookie[1];
$this->expiring = $cookie[2];
$this->data = $this->read( $this->id );
// If the user has logged in, update the session data.
$update_id = $this->maybe_update_id();
// If the session is nearing expiration, update the session.
$extend_expiration = $this->maybe_extend_expiration();
// If either of these two items are true, the cookie needs to be updated.
$set_cookie = $update_id || $extend_expiration;
} else {
$this->id = $this->generate_id();
$this->data = array();
$this->set_expiration();
/**
* Defer emitting the session cookie until session data is actually written.
*
* The session stays in memory only (no `Set-Cookie` header, no database row)
* until `set()` stores something, which keeps anonymous, cache-eligible
* responses free of a `Set-Cookie` header. The cookie is emitted from `set()`
* the moment the first piece of data is written.
*/
$this->is_new = true;
$set_cookie = false;
}
if ( $set_cookie ) {
$this->set_cookie();
}
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |