From 1c7438f08bf289c08d5d1c466316850831b9b0ed Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Oct 2013 15:21:21 +0300 Subject: Added class reference to the session docs Signed-off-by: Michael --- user_guide_src/source/libraries/sessions.rst | 193 ++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 4 deletions(-) (limited to 'user_guide_src') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 51bcc8022..3dc067a70 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -50,13 +50,13 @@ What is Session Data? A *session*, as far as CodeIgniter is concerned, is simply an array containing the following information: -* The user's unique Session ID (this is a statistically random string +- The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes) -* The user's IP Address -* The user's User Agent data (the first 120 characters of the browser +- The user's IP Address +- The user's User Agent data (the first 120 characters of the browser data string) -* The "last activity" time stamp. +- The "last activity" time stamp. The above data is stored in a cookie as a serialized array with this prototype:: @@ -486,3 +486,188 @@ without making it the initially loaded driver, set 'sess_valid_drivers' in your config.php file to an array including your driver name:: $config['sess_valid_drivers'] = array('sess_driver'); + + + +*************** +Class Reference +*************** + +.. class:: CI_Session + +Userdata +-------- + + .. method:: set_userdata($newdata = array(), $newval) + + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :returns: void + + Sets items into session example usages:: + + $this->session->set_userdata('user', 'example@example.com'); + // adds item user with value example@example.com to the session + + $this->session->set_userdata(array('user'=>'example@example.com')); + // does the same as the above example - adds item user with value example@example.com to the session + + .. method:: userdata($item) + + :param string $item: name of session item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->userdata('user'); + //returns example@example.com considering the set_userdata example. + + .. method:: unset_userdata($item) + + :param mixed $item: name of item or array of items + :returns: void + + Unsets previously setted items from the session. Example:: + + $this->session->unset_userdata('user'); + //unsets 'user' from session data. + + $this->session->unset_userdata(array('user', 'useremail')); + //unsets both 'user' nad 'useremail' from the session data. + + .. method:: has_userdata($item) + + :param string $item: name of item + :returns: bool + + Checks if an item exists in the session. + + .. method:: all_userdata() + + :returns: array + + Retruns array of userdata session items + + + +Flashdata +--------- +.. note:: the flashdata items are available only one server request + + .. method:: set_flashdata($newdata = array(), $newval) + + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :returns: void + + Sets items into session flashdata example usages:: + + $this->session->set_flashdata('message', 'Test message.'); + // adds item 'message' with value 'Test message.' to the session flashdata + + $this->session->set_flashdata(array('message'=>'Test message.')); + // does the same as the above example - adds item 'message' with value 'Test message.' + to the session flashdata + + .. method:: flashdata($item) + + :param string $item: name of session item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->flashdata('message'); + //returns 'Test message.' considering the set_flashdata example. + + .. method:: has_flashdata($item) + + :param string $item: name of item + :returns: bool + + Checks if an item exists in the session flashdata. + + .. method:: all_flashdata() + + :returns: array + + Retruns array of flashdata session items + + .. method:: keep_flashdata($item) + + :param mixed $item: name of item or array of flashdata items + :returns: void + + Keeps items into flashdata for one more request + + +Tempdata +-------- + + .. method:: set_tempdata($newdata = array(), $newval, $expires) + + :param mixed $newdata: Item name or array of items + :param string $newval: Item value or empty string (not required if $newdata is array) + :param int $expires: lifetime in seconds (0 for default) + :returns: void + + Sets items into session tempdata example:: + + $this->session->set_tempdata('message', 'Test message.', '60'); + // adds item 'message' with value 'Test message.' to the session tempdata for 60 seconds + + $this->session->set_tempdata(array('message'=>'Test message.')); + // does the same as the above example - adds item 'message' with value 'Test message.' + to the session tempdata for the default value of + + .. method:: tempdata($item) + + :param string $item: name of tempdata item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->tempdata('message'); + //returns 'Test message.' considering the set_tempdata example. + + .. method:: unset_tempdata($item) + + :param mixed $item: name of item or array of items + :returns: void + + Unsets previously setted items from the tempdata. Example:: + + $this->session->unset_tempdata('user'); + //unsets 'user' from tempdata. + + $this->session->unset_tempdata(array('user', 'useremail')); + //unsets both 'user' nad 'useremail' from the tempdata. + +Session +------- + + .. method:: sess_destroy() + + Destroys current session + .. note:: This function should be the last one called, and even flash variables will no longer be available. + If you only want some items destroyed and not all, use ``unset_userdata()``. + + .. method:: sess_regenerate($destroy) + + :param bool $destroy: Destroy session data flag (default: false) + :returns: void + + Regenerate the current session data + + .. method:: load_driver($driver) + + :param string $driver: Driver name + :returns: object Loaded driver object + + Loads a session storage driver + + .. method:: select_driver($driver) + + :param string $driver: Driver name + :returns: void + + Selects default session storage driver. -- cgit v1.2.3-24-g4f1b