JFactory/getSession
From Joomla! Documentation
< JFactory
Returns a reference to the global session object, only creating it if it doesn't already exist. The object returned will be of type JSession.
Syntax
object JSession getSession( $options )
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $options | array | Array of options. See below for possible options. | array() |
The $options array may contain any of the following entries:
| Name | Description | Default |
|---|---|---|
| name | Name of the session. | |
| id | Unique ID of the session. | |
| expire | Expiry date and time. | |
| security | Comma-separated list of security options (see JSession). |
Example
The following code gets the current session then sets the value of the session variable 'myvar' to 'helloworld'.
$session =& JFactory::getSession(); $session->set( 'myvar', 'helloworld' );
The session variable can be retrieved later in a similar way.
$session =& JFactory::getSession(); echo 'Session variable myvar has value: ' . $session->get( 'myvar', 'empty' );
