PHP Class WP_Session, wp-session-manager

Since: 3.6.0
Inheritance: implements ArrayAccess, implements Iterator, implements Countable
显示文件 Open project: ericmann/wp-session-manager Class Usage Examples

Public Properties

Property Type Description
$session_id string ID of the current session.

Protected Properties

Property Type Description
$exp_variant integer Unix timestamp indicating when the expiration time needs to be reset.
$expires integer Unix timestamp when session expires.

Public Methods

Method Description
cache_expiration ( ) : integer Return the read-only cache expiration value.
get_instance ( ) : boolean | WP_Session Retrieve the current session instance.
json_in ( string $data ) : boolean Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
json_out ( ) : string Output the current container contents as a JSON-encoded string.
regenerate_id ( boolean $delete_old = false ) Regenerate the current session's ID.
reset ( ) Flushes all session variables.
session_started ( ) : boolean Check if a session has been initialized.
write_data ( ) Write the data from the current session to the data storage system.

Protected Methods

Method Description
__construct ( ) Default constructor.
read_data ( ) : array Read data from a transient for the current session.
set_cookie ( ) Set the session cookie
set_expiration ( ) Set both the expiration time and the expiration variant.

Method Details

__construct() protected method

Will rebuild the session collection from the given session ID if it exists. Otherwise, will create a new session with that ID.
protected __construct ( )

cache_expiration() public method

Return the read-only cache expiration value.
public cache_expiration ( ) : integer
return integer

get_instance() public static method

Retrieve the current session instance.
public static get_instance ( ) : boolean | WP_Session
return boolean | WP_Session

json_in() public method

Decodes a JSON string and, if the object is an array, overwrites the session container with its contents.
public json_in ( string $data ) : boolean
$data string
return boolean

json_out() public method

Output the current container contents as a JSON-encoded string.
public json_out ( ) : string
return string

read_data() protected method

Automatically resets the expiration time for the session transient to some time in the future.
protected read_data ( ) : array
return array

regenerate_id() public method

Regenerate the current session's ID.
public regenerate_id ( boolean $delete_old = false )
$delete_old boolean Flag whether or not to delete the old session data from the server.

reset() public method

Flushes all session variables.
public reset ( )

session_started() public method

Check if a session has been initialized.
public session_started ( ) : boolean
return boolean

set_expiration() protected method

If the current time is below the variant, we don't update the session's expiration time. If it's greater than the variant, then we update the expiration time in the database. This prevents writing to the database on every page load for active sessions and only updates the expiration time if we're nearing when the session actually expires. By default, the expiration time is set to 30 minutes. By default, the expiration variant is set to 24 minutes. As a result, the session expiration time - at a maximum - will only be written to the database once every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by the browser, and the old session will be queued for deletion by the garbage collector.
protected set_expiration ( )

write_data() public method

Write the data from the current session to the data storage system.
public write_data ( )

Property Details

$exp_variant protected_oe property

Unix timestamp indicating when the expiration time needs to be reset.
protected int $exp_variant
return integer

$expires protected_oe property

Unix timestamp when session expires.
protected int $expires
return integer

$session_id public_oe property

ID of the current session.
public string $session_id
return string