From f83262eceefb37053a8a025fefff0cbb03985f2f Mon Sep 17 00:00:00 2001 From: Gabriel Potkány Date: Fri, 19 Dec 2014 12:35:00 +0100 Subject: Support for microseconds --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 05442d803..5b2813b83 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -553,6 +553,7 @@ Release Date: Not Released - Added a ``$config['log_file_permissions']`` setting. - Changed the library constructor to try to create the **log_path** directory if it doesn't exist. + - Added support for microseconds ("u" date format character) in ``$config['log_date_format']`` - Added `compatibility layers ` for: -- cgit v1.2.3-24-g4f1b From 9c00ab0ec2c9d909c025bd5dbd34da70bdcb0422 Mon Sep 17 00:00:00 2001 From: Gabriel Potkány Date: Fri, 19 Dec 2014 21:47:55 +0100 Subject: . --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 5b2813b83..eb9d1cd6e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -553,7 +553,7 @@ Release Date: Not Released - Added a ``$config['log_file_permissions']`` setting. - Changed the library constructor to try to create the **log_path** directory if it doesn't exist. - - Added support for microseconds ("u" date format character) in ``$config['log_date_format']`` + - Added support for microseconds ("u" date format character) in ``$config['log_date_format']``. - Added `compatibility layers ` for: -- cgit v1.2.3-24-g4f1b From db037dbd023aeeae6d8643707945882f962b2a44 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Jan 2015 13:45:12 +0200 Subject: [ci skip] Polish changes from PR #3278 --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 42ef52c52..8b4f4039e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -336,7 +336,7 @@ Release Date: Not Released - Class properties *wm_font_color*, *wm_shadow_color* and *wm_use_drop_shadow* are now protected, to avoid breaking the ``text_watermark()`` method if they are set manually after initialization. - If property *maintain_ratio* is set to TRUE, ``image_reproportion()`` now doesn't need both width and height to be specified. - Property *maintain_ratio* is now taken into account when resizing images using ImageMagick library. - - Added support for maintaining transparency for PNG images in method ``text_watermark()``. + - Added support for maintaining transparency for PNG images when watermarking. - Added a **file_permissions** setting. - :doc:`Form Validation Library ` changes include: -- cgit v1.2.3-24-g4f1b From 934d6d9797f4dadd4e4d05b12bc4d7309fedb6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Jan 2015 15:03:10 +0200 Subject: [ci skip] Make it clear that PHP <5.4 usage is discouraged Related: #3450 --- user_guide_src/source/contributing/index.rst | 8 ++++---- user_guide_src/source/general/requirements.rst | 11 ++++++++--- user_guide_src/source/general/styleguide.rst | 8 ++++---- 3 files changed, 16 insertions(+), 11 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/contributing/index.rst b/user_guide_src/source/contributing/index.rst index 89bceaa61..e88147753 100644 --- a/user_guide_src/source/contributing/index.rst +++ b/user_guide_src/source/contributing/index.rst @@ -92,10 +92,10 @@ must also be updated for every change. Also PHPDoc blocks must be maintained. Compatibility ============= -CodeIgniter recommends PHP 5.4 or newer to be used, but is compatible with -PHP 5.2.4 so all code supplied must stick to this requirement. If PHP 5.3 -(and above) functions or features are used then there must be a fallback -for PHP 5.2.4. +CodeIgniter recommends PHP 5.4 or newer to be used, but it should be +compatible with PHP 5.2.4 so all code supplied must stick to this +requirement. If PHP 5.3 (and above) functions or features are used then +there must be a fallback for PHP 5.2.4. Branching ========= diff --git a/user_guide_src/source/general/requirements.rst b/user_guide_src/source/general/requirements.rst index 1cb5938aa..e3f73dba8 100644 --- a/user_guide_src/source/general/requirements.rst +++ b/user_guide_src/source/general/requirements.rst @@ -2,10 +2,15 @@ Server Requirements ################### -- `PHP `_ version 5.4 or newer is recommended and 5.2.4 as the absolute minimum required. -- A Database is required for most web application programming. +`PHP `_ version 5.4 or newer is recommended. + +It should work on 5.2.4 as well, but we strongly advise you NOT to run +such old versions of PHP, because of potential security and performance +issues, as well as missing features. + +A database is required for most web application programming. +Currently supported databases are: - Currently supported databases are: - MySQL (5.1+) via the *mysql* (deprecated), *mysqli* and *pdo* drivers - Oracle via the *oci8* and *pdo* drivers - PostgreSQL via the *postgre* and *pdo* drivers diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index 3d8f0a78a..b27031a7b 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -368,10 +368,10 @@ inability for CodeIgniter to send proper headers. Compatibility ============= -CodeIgniter recommends PHP 5.4 or newer to be used, but the absolute -minimum version required is 5.2.4. Your code must either be compatible -with this minimum requirement, provide a suitable fallback, or be an -optional feature that dies quietly without affecting a user's application. +CodeIgniter recommends PHP 5.4 or newer to be used, but it should be +compatible with PHP 5.2.4. Your code must either be compatible with this +requirement, provide a suitable fallback, or be an optional feature that +dies quietly without affecting a user's application. Additionally, do not use PHP functions that require non-default libraries to be installed unless your code contains an alternative method when the -- cgit v1.2.3-24-g4f1b From 973a6542e0e447c811818969108bdea78d9ca9f7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 13:25:24 +0200 Subject: feature/session (#3073): Update config file and session docs Upgrade instructions are still pending. --- user_guide_src/source/libraries/sessions.rst | 1149 ++++++++++++++++---------- 1 file changed, 727 insertions(+), 422 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index f05f86af1..36b5415ac 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -3,11 +3,18 @@ Session Driver ############## The Session class permits you maintain a user's "state" and track their -activity while they browse your site. CodeIgniter offers two default -session drivers: the classic `Cookie Driver`_, and the `Native Driver`_, -which supports usage of the native PHP Session mechanism. In addition, -you may create your own `Custom Drivers`_ to store session data however -you wish, while still taking advantage of the features of the Session class. +activity while they browse your site. + +CodeIgniter comes with a few session storage drivers: + + - files (default; file-system based) + - database + - redis + - memcached + +In addition, you may create your own, custom session drivers based on other +kinds of storage, while still taking advantage of the features of the +Session class. .. contents:: :local: @@ -23,122 +30,132 @@ Using the Session Class Initializing a Session ====================== -Sessions will typically run globally with each page load, so the session -class must either be :doc:`initialized <../general/drivers>` in your -:doc:`controller <../general/controllers>` constructors, or it can be -:doc:`auto-loaded <../general/autoloader>` by the system. For the most -part the session class will run unattended in the background, so simply -initializing the class will cause it to read, create, and update -sessions. +Sessions will typically run globally with each page load, so the Session +class should either be initialized in your :doc:`controller +<../general/controllers>` constructors, or it can be :doc:`auto-loaded +<../general/autoloader>` by the system. +For the most part the session class will run unattended in the background, +so simply initializing the class will cause it to read, create, and update +sessions when necessary. To initialize the Session class manually in your controller constructor, -use the ``$this->load->driver`` function:: +use the ``$this->load->library()`` method:: - $this->load->driver('session'); + $this->load->library('session'); Once loaded, the Sessions library object will be available using:: $this->session +.. important:: Because the :doc:`Loader Class <../loader>` is instantiated + by CodeIgniter's base controller, make sure to call + ``parent::__construct()`` before trying to load a library from + inside a controller constructor. + How do Sessions work? ===================== When a page is loaded, the session class will check to see if valid -session data exists in the user's session. If sessions data does **not** -exist (or if it has expired) a new session will be created and saved. -If a session does exist, its information will be updated. With each update, -the session_id will be regenerated. +session cookie is sent by the user's browser. If a sessions cookie does +**not** exist (or if it doesn't match one stored on the server or has +expired) a new session will be created and saved. + +If a valid session does exist, its information will be updated. With each +update, the session ID may be regenerated if configured to do so. It's important for you to understand that once initialized, the Session class runs automatically. There is nothing you need to do to cause the -above behavior to happen. You can, as you'll see below, work with -session data or even add your own data to a user's session, but the -process of reading, writing, and updating a session is automatic. +above behavior to happen. You can, as you'll see below, work with session +data, but the process of reading, writing, and updating a session is +automatic. + +.. note:: Under CLI, the Session library will automatically halt itself, + as this is a concept based entirely on the HTTP protocol. 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 - 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 - data string) -- The "last activity" time stamp. - -The above data is stored in a cookie as a serialized array with this -prototype:: - - [array] - ( - 'session_id' => random hash, - 'ip_address' => 'string - user IP address', - 'user_agent' => 'string - user agent data', - 'last_activity' => timestamp - ) - -.. note:: Sessions are only updated every five minutes by default to - reduce processor load. If you repeatedly reload a page you'll notice - that the "last activity" time only updates if five minutes or more has - passed since the last time the cookie was written. This time is - configurable by changing the $config['sess_time_to_update'] line in - your system/config/config.php file. +Session data is simply an array associated with a particular session ID +(cookie). + +If you've used sessions in PHP before, you should be familiar with PHP's +`$_SESSION superglobal `_ +(if not, please read the content on that link). + +CodeIgniter gives access to its session data through the same means, as it +uses the session handlers' mechanism provided by PHP. Using session data is +as simple as manipulating (read, set and unset values) the ``$_SESSION`` +array. + +In addition, CodeIgniter also provides 2 special types of session data +that are further explained below: flashdata and tempdata. + +.. note:: In previous versions, regular session data in CodeIgniter was + referred to as 'userdata'. Have this in mind if that term is used + elsewhere in the manual. Most of it is written to explain how + the custom 'userdata' methods work. Retrieving Session Data ======================= -Any piece of information from the session array is available using the -following function:: +Any piece of information from the session array is available through the +``$_SESSION`` superglobal:: + + $_SESSION['item'] + +Or through the magic getter:: + + $this->session->item + +And for backwards compatibility, through the ``userdata()`` method:: $this->session->userdata('item'); -Where item is the array index corresponding to the item you wish to -fetch. For example, to fetch the session ID you will do this:: +Where item is the array key corresponding to the item you wish to fetch. +For example, to assign a previously stored 'name' item to the ``$name`` +variable, you will do this:: + + $name = $_SESSION['name']; + + // or: - $session_id = $this->session->userdata('session_id'); + $name = $this->session->name -.. note:: The function returns NULL if the item you are - trying to access does not exist. + // or: + + $name = $this->session->userdata('name'); + +.. note:: The ``userdata()`` method returns NULL if the item you are trying + to access does not exist. If you want to retrieve all of the existing userdata, you can simply -omit the item key parameter:: +omit the item key (magic getter only works for properties):: - $this->session->userdata(); + $_SESSION - /** - * Produces something similar to: - * - * Array - * ( - * [session_id] => 4a5a5dca22728fb0a84364eeb405b601 - * [ip_address] => 127.0.0.1 - * [user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; - * [last_activity] => 1303142623 - * ) - */ - -Adding Custom Session Data -========================== + // or: + + $this->session->userdata(); -A useful aspect of the session array is that you can add your own data -to it and it will be stored in the user's cookie. Why would you want to -do this? Here's one example: +Adding Session Data +=================== Let's say a particular user logs into your site. Once authenticated, you -could add their username and email address to the session, making -that data globally available to you without having to run a database -query when you need it. +could add their username and e-mail address to the session, making that +data globally available to you without having to run a database query when +you need it. + +You can simply assign data to the ``$_SESSION`` array, as with any other +variable. Or as a property of ``$this->session``. -To add your data to the session array involves passing an array -containing your new data to this function:: +Alternatively, the old method of assigning it as "userdata" is also +available. That however passing an array containing your new data to the +``set_userdata()`` method:: $this->session->set_userdata($array); -Where $array is an associative array containing your new data. Here's an -example:: +Where ``$array`` is an associative array containing your new data. Here's +an example:: $newdata = array( 'username' => 'johndoe', @@ -149,68 +166,104 @@ example:: $this->session->set_userdata($newdata); If you want to add userdata one value at a time, ``set_userdata()`` also -supports this syntax. - -:: +supports this syntax:: $this->session->set_userdata('some_name', 'some_value'); -If you want to verify that a userdata value exists, call ``has_userdata()``. +If you want to verify that a session value exists, simply check with +``isset()``:: -:: + // returns FALSE if the 'some_name' item doesn't exist or is NULL, + // TRUE otherwise: + isset($_SESSION['some_name']) + +Or you can call ``has_userdata()``:: $this->session->has_userdata('some_name'); Removing Session Data ===================== -Just as set_userdata() can be used to add information into a session, -unset_userdata() can be used to remove it, by passing the session key. -For example, if you wanted to remove 'some_name' from your session -information:: +Just as with any other variable, unsetting a value in ``$_SESSION`` can be +done through ``unset()``:: - $this->session->unset_userdata('some_name'); + unset($_SESSION['some_name']); + // or multiple values: -This function can also be passed an associative array of items to unset. + unset( + $_SESSION['some_name'], + $_SESSION['another_name'] + ); -:: +Also, just as ``set_userdata()`` can be used to add information to a +session, ``unset_userdata()`` can be used to remove it, by passing the +session key. For example, if you wanted to remove 'some_name' from your +session data array:: + + $this->session->unset_userdata('some_name'); + +This method also accepts an associative array of items to unset:: $array_items = array('username' => '', 'email' => ''); $this->session->unset_userdata($array_items); - Flashdata ========= CodeIgniter supports "flashdata", or session data that will only be -available for the next server request, and are then automatically -cleared. These can be very useful, and are typically used for -informational or status messages (for example: "record 2 deleted"). +available for the next request, and is then automatically cleared. + +This can be very useful, especially for one-time informational, error or +status messages (for example: "Record 2 deleted"). + +It should be noted that flashdata variables are regular session vars, +only marked in a specific way under the '__ci_vars' key (please don't touch +that one, you've been warned). -.. note:: Flash variables are prefaced with "flash\_" so avoid this prefix - in your own session names. +To mark an existing item as "flashdata":: + + $this->session->mark_as_flash('item'); + +If you want to mark multiple items as flashdata, simply pass the keys as an +array:: + + $this->session->mark_as_flash(array('item', 'item2')); To add flashdata:: - $this->session->set_flashdata('item', 'value'); + $_SESSION['item'] = 'value'; + $this->session->mark_as_flash('item'); +Or alternatively, using the ``set_flashdata()`` method:: + + $this->session->set_flashdata('item', 'value'); You can also pass an array to ``set_flashdata()``, in the same manner as ``set_userdata()``. -To read a flashdata variable:: +Reading flashdata variables is the same as reading regular session data +through ``$_SESSION``:: + + $_SESSION['item'] + +.. important:: The ``userdata()`` method will NOT return flashdata items. + +However, if you want to be sure that you're reading "flashdata" (and not +any other kind), you can also use the ``flashdata()`` method:: $this->session->flashdata('item'); -An array of all flashdata can be retrieved as follows:: +Or to get an array with all flashdata, simply omit the key parameter:: $this->session->flashdata(); +.. note:: The ``flashdata()`` method returns NULL if the item cannot be + found. If you find that you need to preserve a flashdata variable through an -additional request, you can do so using the ``keep_flashdata()`` function. +additional request, you can do so using the ``keep_flashdata()`` method. You can either pass a single item or an array of flashdata items to keep. :: @@ -218,8 +271,6 @@ You can either pass a single item or an array of flashdata items to keep. $this->session->keep_flashdata('item'); $this->session->keep_flashdata(array('item1', 'item2', 'item3')); -.. note:: The function will return NULL if the item cannot be found. - Tempdata ======== @@ -227,22 +278,56 @@ CodeIgniter also supports "tempdata", or session data with a specific expiration time. After the value expires, or the session expires or is deleted, the value is automatically removed. +Similarly to flashdata, tempdata variables are regular session vars that +are marked in a specific way under the '__ci_vars' key (again, don't touch +that one). + +To mark an existing item as "tempdata", simply pass its key and expiry time +(in seconds!) to the ``mark_as_temp()`` method:: + + // 'item' will be erased after 300 seconds + $this->session->mark_as_temp('item', 300); + +You can mark multiple items as tempdata in two ways, depending on whether +you want them all to have the same expiry time or not:: + + // Both 'item' and 'item2' will expire after 300 seconds + $this->session->mark_as_temp(array('item', 'item2'), 300); + + // 'item' will be erased after 300 seconds, while 'item2' + // will do so after only 240 seconds + $this->session->mark_as_temp(array( + 'item' => 300, + 'item2' => 240 + )); + To add tempdata:: - $expire = 300; // Expire in 5 minutes + $_SESSION['item'] = 'value'; + $this->session->mark_as_temp('item', 300); // Expire in 5 minutes - $this->session->set_tempdata('item', 'value', $expire); +Or alternatively, using the ``set_tempdata()`` method:: + + $this->session->set_tempdata('item', 'value', 300); You can also pass an array to ``set_tempdata()``:: $tempdata = array('newuser' => TRUE, 'message' => 'Thanks for joining!'); - $this->session->set_tempdata($tempdata, '', $expire); + $this->session->set_tempdata($tempdata, NULL, $expire); + +.. note:: If the expiration is omitted or set to 0, the default + time-to-live value of 300 seconds (or 5 minutes) will be used. + +To read a tempdata variable, again you can just access it through the +``$_SESSION`` superglobal array:: -.. note:: If the expiration is omitted or set to 0, the default expiration of - 5 minutes will be used. + $_SESSION['item'] -To read a tempdata variable:: +.. important:: The ``userdata()`` method will NOT return tempdata items. + +Or if you want to be sure that you're reading "flashdata" (and not any +other kind), you can also use the ``tempdata()`` method:: $this->session->tempdata('item'); @@ -250,453 +335,673 @@ And of course, if you want to retrieve all existing tempdata:: $this->session->tempdata(); -If you need to remove a tempdata value before it expires, -use ``unset_tempdata()``:: +.. note:: The ``tempdata()`` method returns NULL if the item cannot be + found. + +If you need to remove a tempdata value before it expires, you can directly +unset it from the ``$_SESSION`` array:: + + unset($_SESSION['item']); + +However, this won't remove the marker that makes this specific item to be +tempdata (it will be invalidated on the next HTTP request), so if you +intend to reuse that same key in the same request, you'd want to use +``unset_tempdata()``:: $this->session->unset_tempdata('item'); Destroying a Session ==================== -To clear the current session:: +To clear the current session (for example, during a logout), you may +simply use either PHP's `session_destroy() `_ +function, or the ``sess_destroy()`` method. Both will work in exactly the +same way:: + + session_destroy(); + + // or $this->session->sess_destroy(); -.. 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()``. +.. note:: This must be the last session-related operation that you do + during the same request. All session data (including flashdata and + tempdata) will be destroyed permanently and functions will be + unusable during the same request after you destroy the session. + +Accessing session metadata +========================== + +In previous CodeIgniter versions, the session data array included 4 items +by default: 'session_id', 'ip_address', 'user_agent', 'last_activity'. + +This was due to the specifics of how sessions worked, but is now no longer +necessary with our new implementation. However, it may happen that your +application relied on these values, so here are alternative methods of +accessing them:: + + - session_id: ``session_id()`` + - ip_address: ``$_SERVER['REMOTE_ADDR']`` + - user_agent: ``$this->input->user_agent()`` (unused by sessions) + - last_activity: Depends on the storage, no straightforward way. Sorry! Session Preferences =================== +CodeIgniter will usually make everything work out of the box. However, +Sessions are a very sensitive component of any application, so some +careful configuration must be done. Please take your time to consider +all of the options and their effects. + You'll find the following Session related preferences in your -*application/config/config.php* file: - -=========================== =============== =========================== ========================================================================== -Preference Default Options Description -=========================== =============== =========================== ========================================================================== -**sess_driver** cookie cookie/native/*custom* The initial session driver to load. -**sess_valid_drivers** cookie, native None Additional valid drivers which may be loaded. -**sess_cookie_name** ci_session None The name you want the session cookie saved as (data for Cookie driver or - session ID for Native driver). -**sess_expiration** 7200 None The number of seconds you would like the session to last. The default - value is 2 hours (7200 seconds). If you would like a non-expiring - session set the value to zero: 0 -**sess_expire_on_close** FALSE TRUE/FALSE (boolean) Whether to cause the session to expire automatically when the browser - window is closed. -**sess_encrypt_cookie** FALSE TRUE/FALSE (boolean) Whether to encrypt the session data (Cookie driver only). -**sess_use_database** FALSE TRUE/FALSE (boolean) Whether to save the session data to a database. You must create the - table before enabling this option (Cookie driver only). -**sess_table_name** ci_sessions Any valid SQL table name The name of the session database table (Cookie driver only). -**sess_time_to_update** 300 Time in seconds This options controls how often the session class will regenerate itself - and create a new session ID. Setting it to 0 will disable session - ID regeneartion. -**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to match the user's IP address when reading the session data. - Note that some ISPs dynamically changes the IP, so if you want a - non-expiring session you will likely set this to FALSE. -**sess_match_useragent** TRUE TRUE/FALSE (boolean) Whether to match the User Agent when reading the session data. -=========================== =============== =========================== ========================================================================== +**application/config/config.php** file: + +======================== =============== ======================================== ============================================================================================ +Preference Default Options Description +======================== =============== ======================================== ============================================================================================ +**sess_driver** files files/database/redis/memcached/*custom* The session storage driver to use. +**sess_cookie_name** ci_session [A-Za-z_-] characters only The name used for the session cookie. +**sess_expiration** 7200 (2 hours) Time in seconds (integer) The number of seconds you would like the session to last. + If you would like a non-expiring session (until browser is closed) set the value to zero: 0 +**sess_save_path** NULL None Specifies the storage location, depends on the driver being used. +**sess_time_to_update** 300 Time in seconds (integer) This options controls how often the session class will regenerate itself and create a new + session ID. Setting it to 0 will disable session ID regeneartion. +**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to validate the user's IP address when reading the session cookie. + Note that some ISPs dynamically changes the IP, so if you want a non-expiring session you + will likely set this to FALSE. +======================== =============== ======================================== ============================================================================================ + +.. note:: As a last resort, the Session library will try to fetch PHP's + session related INI settings, as well as legacy CI settings such as + 'sess_expire_on_close' when any of the above is not configured. + However, you should never rely on this behavior as it can cause + unexpected results or be changed in the future. Please configure + everything properly. In addition to the values above, the cookie and native drivers apply the following configuration values shared by the :doc:`Input ` and :doc:`Security ` classes: -=========================== =============== ========================================================================== -Preference Default Description -=========================== =============== ========================================================================== -**cookie_prefix** '' Set a cookie name prefix in order to avoid name collisions -**cookie_domain** '' The domain for which the session is applicable -**cookie_path** / The path to which the session is applicable -=========================== =============== ========================================================================== +================== =============== =========================================================================== +Preference Default Description +================== =============== =========================================================================== +**cookie_domain** '' The domain for which the session is applicable +**cookie_path** / The path to which the session is applicable +**cookie_secure** FALSE Whether to create the session cookie only on encrypted (HTTPS) connections +================== =============== =========================================================================== + +.. note:: The 'cookie_httponly' setting doesn't have an effect on sessions. + Instead the HttpOnly parameter is always enabled, for security + reasons. Additionaly, the 'cookie_prefix' setting is completely + ignored. Session Drivers =============== -By default, the `Cookie Driver`_ is loaded when a session is initialized. -However, any valid driver may be selected with the $config['sess_driver'] -line in your config.php file. - -The session driver library comes with the cookie and native drivers -installed, and `Custom Drivers`_ may also be installed by the user. - -Typically, only one driver will be used at a time, but CodeIgniter does -support loading multiple drivers. If a specific valid driver is called, it -will be automatically loaded. Or, an additional driver may be explicitly -loaded by ``calling load_driver()``:: - - $this->session->load_driver('native'); - -The Session library keeps track of the most recently selected driver to call -for driver methods. Normally, session class methods are called directly on -the parent class, as illustrated above. However, any methods called through -a specific driver will select that driver before invoking the parent method. - -So, alternation between multiple drivers can be achieved by specifying which -driver to use for each call:: - - $this->session->native->set_userdata('foo', 'bar'); - - $this->session->cookie->userdata('foo'); - - $this->session->native->unset_userdata('foo'); - -Notice in the previous example that the *native* userdata value 'foo' -would be set to 'bar', which would NOT be returned by the call for -the *cookie* userdata 'foo', nor would the *cookie* value be unset by -the call to unset the *native* 'foo' value. The drivers maintain independent -sets of values, regardless of key names. - -A specific driver may also be explicitly selected for use by pursuant -methods with the ``select_driver()`` call:: - - $this->session->select_driver('native'); - - $this->session->userdata('item'); // Uses the native driver - -Cookie Driver -------------- - -The Cookie driver stores session information for each user as serialized -(and optionally encrypted) data in a cookie. It can also store the session -data in a database table for added security, as this permits the session ID -in the user's cookie to be matched against the stored session ID. By default -only the cookie is saved. If you choose to use the database option you'll -need to create the session table as indicated below. - -If you have the encryption option enabled, the serialized array will be -encrypted before being stored in the cookie, making the data highly -secure and impervious to being read or altered by someone. More info -regarding encryption can be :doc:`found here `, although -the Session class will take care of initializing and encrypting the data -automatically. - -.. note:: Even if you are not using encrypted sessions, you must set - an :doc:`encryption key <./encryption>` in your config file which is used - to aid in preventing session data manipulation. - -.. note:: Cookies can only hold 4KB of data, so be careful not to exceed - the capacity. The encryption process in particular produces a longer - data string than the original so keep careful track of how much data you - are storing. - -Saving Session Data to a Database -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -While the session data array stored in the user's cookie contains a -Session ID, unless you store session data in a database there is no way -to validate it. For some applications that require little or no -security, session ID validation may not be needed, but if your -application requires security, validation is mandatory. Otherwise, an -old session could be restored by a user modifying their cookies. - -When session data is available in a database, every time a valid session -is found in the user's cookie, a database query is performed to match -it. If the session ID does not match, the session is destroyed. Session -IDs can never be updated, they can only be generated when a new session -is created. - -In order to store sessions, you must first create a database table for -this purpose. Here is the basic prototype (for MySQL) required by the -session class:: - - CREATE TABLE IF NOT EXISTS `ci_sessions` ( - session_id varchar(40) DEFAULT '0' NOT NULL, - ip_address varchar(45) DEFAULT '0' NOT NULL, - user_agent varchar(120) NOT NULL, - last_activity int(10) unsigned DEFAULT 0 NOT NULL, - user_data text NOT NULL, - PRIMARY KEY (session_id, ip_address, user_agent), - KEY `last_activity_idx` (`last_activity`) +As already mentioned, the Session library comes with 4 drivers, or storage +engines, that you can use: + + - files + - database + - redis + - memcached + +By default, the `Files Driver`_ will be used when a session is initialized, +because it is the most safe choice and is expected to work everywhere +(virtually every environment has a file system). + +However, any other driver may be selected via the ``$config['sess_driver']`` +line in your **application/config/config.php** file, if you chose to do so. +Have it in mind though, every driver has different caveats, so be sure to +get yourself familiar with them (below) before you make that choice. + +In addition, you may also create and use `Custom Drivers`_, if the ones +provided by default don't satisfy your use case. + +.. note:: In previous CodeIgniter versions, a different, "cookie driver" + was the only option and we have received negative feedback on not + providing that option. While we do listen to feedback from the + community, we want to warn you that it was dropped because it is + **unsafe** and we advise you NOT to try to replicate it via a + custom driver. + +Files Driver +------------ + +The 'files' driver uses your file system for storing session data. + +It can safely be said that it works exactly like PHP's own default session +implementation, but in case this is an important detail for you, have it +mind that it is in fact not the same code and it has some limitations +(and advantages). + +To be more specific, it doesn't support PHP's `directory level and mode +formats used in session.save_path +`_, +and it has most of the options hard-coded for safety. Instead, only +absolute paths are supported for ``$config['sess_save_path']``. + +Another important thing that you should know, is to make sure that you +don't use a publicly-readable or shared directory for storing your session +files. Make sure that *only you* have access to see the contents of your +chosen *sess_save_path* directory. Otherwise, anybody who can do that, can +also steal any of the current sessions (also known as "session fixation" +attack). + +On UNIX-like operating systems, this is usually achieved by setting the +0600 mode permissions on that directory via the `chmod` command, which +allows only the directory's owner to perform read and write operations on +it. But be careful because the system user *running* the script is usually +not your own, but something like 'www-data' instead, so only setting those +permissions will probable break your application. + +Instead, you should do something like this, depending on your environment +:: + + mkdir //sessions/ + chmod 0600 //sessions/ + chown www-data //sessions/ + +Bonus Tip +^^^^^^^^^ + +Some of you will probably opt to choose another session driver because +file storage is usually slower. This is only half true. + +A very basic test will probably trick you into believing that an SQL +database is faster, but in 99% of the cases, this is only true while you +only have a few current sessions. As the sessions count and server loads +increase - which is the time when it matters - the file system will +consistently outperform almost all relational database setups. + +In addition, if performance is your only concern, you may want to look +into using `tmpfs `_, +(warning: external resource), which can make your sessions blazing fast. + +Database Driver +--------------- + +The 'database' driver uses a relational database such as MySQL or +PostgreSQL to store sessions. This is a popular choice among many users, +because it allows the developer easy access to the session data within +an application - it is just another table in your database. + +However, there are some conditions that must be met: + + - Only your **default** database connection (or the one that you access + as ``$this->db`` from your controllers) can be used. + - You can NOT use a persistent connection. + - You must have the :doc:`Query Builder ` + enabled. + +In order to use the 'database' session driver, you must also create this +table that we already mentioned and then set it as your +``$config['sess_save_path']`` value. +For example, if you would like to use 'ci_sessions' as your table name, +you would do this: + + $config['sess_driver'] = 'database'; + $config['sess_save_path'] = 'ci_sessions'; + +.. note:: If you've upgraded from a previous version of CodeIgniter and + you don't have 'sess_save_path' configured, then the Session + library will look for the old 'sess_table_name' setting and use + it instead. Please don't rely on this behavior as it will get + removed in the future. + +And then of course, create the database table ... + +For MySQL:: + + CREATE TABLE IF NOT EXISTS `ci_sessions` ( + `session_id` varchar(40) NOT NULL, + `ip_address` varchar(45) NOT NULL, + `timestamp` int(10) unsigned DEFAULT 0 NOT NULL, + `data` blob DEFAULT '' NOT NULL, + PRIMARY KEY (session_id, ip_address), + KEY `ci_sessions_timestamp` (`timestamp`) ); -Or if you're using PostgreSQL:: +For PostgreSQL:: - CREATE TABLE ci_sessions ( - session_id varchar(40) DEFAULT '0' NOT NULL, - ip_address varchar(45) DEFAULT '0' NOT NULL, - user_agent varchar(120) NOT NULL, - last_activity bigint DEFAULT 0 NOT NULL, - user_data text NOT NULL, - PRIMARY KEY (session_id) + CREATE TABLE "ci_sessions" ( + "session_id" varchar(40) NOT NULL, + "ip_address" varchar(45) NOT NULL, + "timestamp" bigint DEFAULT 0 NOT NULL, + "data" text DEFAULT '' NOT NULL, + PRIMARY KEY ("session_id") ); - CREATE INDEX last_activity_idx ON ci_sessions(last_activity); + CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp"); + +However, if you want to turn on the *sess_match_ip* setting, you should +also do the following, after creating the table:: + + // Works both on MySQL and PostgreSQL + ALTER TABLE ci_sessions ADD CONSTRAINT ci_sessions_id_ip UNIQUE (session_id, ip_address); + +.. important:: Only MySQL and PostgreSQL databases are officially + supported, due to lack of locking mechanisms on other platforms. + Using sessions without locks can cause all sorts of problems, + especially with heavy usage of AJAX, and we will not support + such cases. + +Redis Driver +------------ + +Redis is a storage engine typically used for caching and popular because +of its high performance, which is also probably your reason to use the +'redis' session driver. + +The downside is that it is not as ubiquitous as relational databases and +requires the `phpredis `_ PHP +extension to be installed on your system, and that one doesn't come +bundled with PHP. +Chances are, you're only be using the 'redis' driver only if you're already +both familiar with Redis and using it for other purposes. + +Just as with the 'files' and 'database' drivers, you must also configure +the storage location for your sessions via the +``$config['sess_save_path']`` setting. +The format here is a bit different and complicated at the same time. It is +best explained by the *phpredis* extension's README file, so we'll simply +link you to it: + + https://github.com/phpredis/phpredis#php-session-handler + +.. warning:: CodeIgniter's Session library does NOT use the actual 'redis' + ``session.save_handler``. Take note **only** of the path format in + the link above. -.. note:: By default the table is called ci_sessions, but you can name - it anything you want as long as you update the - *application/config/config.php* file so that it contains the name - you have chosen. Once you have created your database table you - can enable the database option in your config.php file as follows:: +For the most common case however, a simple ``host:port`` pair should be +sufficient:: - $config['sess_use_database'] = TRUE; + $config['sess_driver'] = 'redis'; + $config['sess_save_path'] = 'tcp://localhost:6379'; - Once enabled, the Session class will store session data in the DB. +Memcached Driver +---------------- - Make sure you've specified the table name in your config file as well:: +The 'memcached' driver is very similar to the 'redis' one in all of its +properties, except perhaps for availability, because PHP's `Memcached +`_ extension is distributed via PECL and some +Linux distrubutions make it available as an easy to install package. - $config['sess_table_name'] = 'ci_sessions'; +Other than that, and without any intentional bias towards Redis, there's +not much different to be said about Memcached - it is also a popular +product that is usually used for caching and famed for its speed. -.. note:: The Cookie driver has built-in garbage collection which clears - out expired sessions so you do not need to write your own routine to do - it. +However, it is worth noting that the only guarantee given by Memcached +is that setting value X to expire after Y seconds will result in it being +deleted after Y seconds have passed (but not necessarily that it won't +expire earlier than that time). This happens very rarely, but should be +considered as it may result in loss of sessions. -Native Driver -------------- +The ``$config['sess_save_path']`` format is fairly straightforward here, +being just a ``host:port`` pair:: -The Native driver relies on native PHP sessions to store data in the -$_SESSION superglobal array. All stored values continue to be available -through $_SESSION, but flash- and temp- data items carry special prefixes. + $config['sess_driver'] = 'memcached'; + $config['sess_save_path'] = 'localhost:11211'; + +Bonus Tip +^^^^^^^^^ + +Multi-server configuration with an optional *weight* parameter as the +third colon-separated (``:weight``) value is also supported, but we have +to note that we haven't tested if that is reliable. + +If you want to experiment with this feature (on your own risk), simply +separate the multiple server paths with commas:: + + // localhost will be given higher priority (5) here, + // compared to 192.0.2.1 with a weight of 1. + $config['sess_save_path'] = 'localhost:11211:5,192.0.2.1:11211:1'; Custom Drivers -------------- -You may also :doc:`create your own <../general/creating_drivers>` custom -session drivers. A session driver basically manages an array of name/value -pairs with some sort of storage mechanism. +You may also create your own, custom session drivers. However, have it in +mind that this is typically not an easy task, as it takes a lot of +knowledge to do it properly. + +You need to know not only how sessions work in general, but also how they +work specifically in PHP, how the underlying storage mechanism works, how +to handle concurrency, avoid deadlocks (but NOT through lack of locks) and +last but not least - how to handle the potential security issues, which +is far from trivial. + +Long story short - if you don't know how to do that already in raw PHP, +you shouldn't be trying to do it within CodeIgniter either. You've been +warned. + +If you only want to add some extra functionality to your sessions, just +extend the base Session class, which is a lot more easier. Read the +:doc:`Creating Libraries <../general/creating_libraries>` article to +learn how to do that. + +Now, to the point - there are three general rules that you must follow +when creating a session driver for CodeIgniter: + + - Put your driver's file under **application/libraries/Session/drivers/** + and follow the naming conventions used by the Session class. + + For example, if you were to create a 'dummy' driver, you would have + a ``Session_dummy_driver`` class name, that is declared in + *application/libraries/Session/drivers/Session_dummy_driver.php*. -To make a new driver, extend CI_Session_driver. Overload the ``initialize()`` -method and read or create session data. Then implement a save handler to -write changed data to storage (sess_save), a destroy handler to remove -deleted data (sess_destroy), a regenerate handler to make a new session ID -(sess_regenerate), and an access handler to expose the data (get_userdata). -Your initial class might look like:: + - Extend the ``CI_Session_driver`` class. - class CI_Session_custom extends CI_Session_driver { + This is just a basic class with a few internal helper methods. It is + also extendable like any other library, if you really need to do that, + but we are not going to explain how ... if you're familiar with how + class extensions/overrides work in CI, then you already know how to do + it. If not, well, you shouldn't be doing it in the first place. - protected function initialize() + + - Implement the `SessionHandlerInterface + `_ interface. + + .. note:: You may notice that ``SessionHandlerInterface`` is provided + by PHP since version 5.4.0. CodeIgniter will automatically declare + the same interface if you're running an older PHP version. + + The link will explain why and how. + +So, based on our 'dummy' driver example above, you'd end up with something +like this:: + + // application/libraries/Session/drivers/Session_dummy_driver.php: + + class CI_Session_dummy_driver extends CI_Session_driver implements SessionHandlerInterface + { + + public function __construct(&$params) + { + // DO NOT forget this + parent::__construct($params); + + // Configuration & other initializations + } + + public function open($save_path, $name) { - // Read existing session data or create a new one + // Initialize storage mechanism (connection) } - public function sess_save() + public function read($session_id) { - // Save current data to storage + // Read session data (if exists), acquire locks } - public function sess_destroy() + public function write($session_id, $session_data) { - // Destroy the current session and clean up storage + // Create / update session data (it might not exist!) } - public function sess_regenerate() + public function close() { - // Create new session ID + // Free locks, close connections / streams / etc. } - public function &get_userdata() + public function destroy($session_id) { - // Return a reference to your userdata array + // Call close() method & destroy data for current session (order may differ) + } + + public function gc($maxlifetime) + { + // Erase data for expired sessions } } -Notice that ``get_userdata()`` returns a reference so the parent library is -accessing the same array the driver object is using. This saves memory -and avoids synchronization issues during usage. +If you've done everything properly, you can now set your *sess_driver* +configuration value to 'dummy' and use your own driver. Congratulations! + +*************** +Class Reference +*************** -Put your driver in the libraries/Session/drivers folder anywhere in your -package paths. This includes the application directory, the system directory, -or any path you add with ``$CI->load->add_package_path()``. Your driver must be -named CI_Session_, and your filename must be Session_.php, -preferably also capitalized, such as:: +.. class:: CI_Session - CI_Session_foo in libraries/Session/drivers/Session_foo.php + .. method:: userdata([$key = NULL]) -Then specify the driver by setting 'sess_driver' in your config.php file or as a -parameter when loading the CI_Session object:: + :param mixed $key: Session item key or NULL + :returns: Value of the specified item key, or an array of all userdata + :rtype: mixed - $config['sess_driver'] = 'foo'; + Gets the value for a specific ``$_SESSION`` item, or an + array of all "userdata" items if not key was specified. + + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. You should + directly access ``$_SESSION`` instead. -OR:: + .. method:: all_userdata() - $CI->load->driver('session', array('sess_driver' => 'foo')); + :returns: An array of all userdata + :rtype: array -The driver specified by 'sess_driver' is automatically included as a valid -driver. However, if you want to make a custom driver available as an option -without making it the initially loaded driver, set 'sess_valid_drivers' in -your config.php file to an array including your driver name:: + Returns an array containing all "userdata" items. - $config['sess_valid_drivers'] = array('sess_driver'); + .. note:: This method is DEPRECATED. Use ``userdata()`` + with no parameters instead. -*************** -Class Reference -*************** + .. method:: &get_usedata() -.. class:: CI_Session + :returns: A reference to ``$_SESSION`` + :rtype: array - .. method:: load_driver($driver) + Returns a reference to the ``$_SESSION`` array. - :param string $driver: Driver name - :returns: Instance of currently loaded session driver - :rtype: mixed + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. - Loads a session storage driver + .. method:: has_userdata($key) - .. method:: select_driver($driver) + :param string $key: Session item key + :returns: TRUE if the specified key exists, FALSE if not + :rtype: bool - :param string $driver: Driver name - :rtype: void + Checks if an item exists in ``$_SESSION``. - Selects default session storage driver. + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. It is just + an alias for ``isset($_SESSION[$key])`` - please + use that instead. - .. method:: sess_destroy() + .. method:: set_userdata($data[, $value = NULL]) + :param mixed $data: An array of key/value pairs to set as session data, or the key for a single item + :param mixed $value: The value to set for a specific session item, if $data is a key :rtype: void - Destroys current session + Assigns data to the ``$_SESSION`` superglobal. - .. note:: This method should be the last one called, and even flash - variables will no longer be available after it is used. - If you only want some items destroyed and not all, use - ``unset_userdata()``. + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. - .. method:: sess_regenerate([$destroy = FALSE]) + .. method:: unset_userdata($key) - :param bool $destroy: Whether to destroy session data + :param mixed $key: Key for the session data item to unset, or an array of multiple keys :rtype: void - Regenerate the current session data. + Unsets the specified key(s) from the ``$_SESSION`` + superglobal. - .. method:: userdata([$item = NULL]) - - :param string $item: Session item name - :returns: Item value if found, NULL if not or an array of all userdata if $item parameter is not used - :rtype: mixed + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. It is just + an alias for ``unset($_SESSION[$key])`` - please + use that instead. - If no parameter is passed, it will return an associative array of all existing userdata. + .. method:: mark_as_flash($key) - Otherwise returns a string containing the value of the passed item or NULL if the item is not found. - Example:: + :param mixed $key: Key to mark as flashdata, or an array of multiple keys + :returns: TRUE on success, FALSE on failure + :rtype: bool - $this->session->userdata('user'); - //returns example@example.com considering the set_userdata example. + Marks a ``$_SESSION`` item key (or multiple ones) as + "flashdata". - .. method:: all_userdata() + .. method:: get_flash_keys() - :returns: An array of all userdata + :returns: Array containing the keys of all "flashdata" items. :rtype: array - Returns an array with all of the session userdata items. + Gets a list of all ``$_SESSION`` that have been marked as + "flashdata". - .. note:: This method is DEPRECATED. Use ``userdata()`` with no parameters instead. + .. method:: umark_flash($key) - .. method:: &get_userdata() + :param mixed $key: Key to be un-marked as flashdata, or an array of multiple keys + :rtype: void - :returns: A reference to the userdata array - :rtype: &array + Unmarks a ``$_SESSION`` item key (or multiple ones) as + "flashdata". - Returns a reference to the userdata array. + .. method:: flashdata([$key = NULL]) - .. method:: set_userdata($newdata[, $newval = '']) + :param mixed $key: Flashdata item key or NULL + :returns: Value of the specified item key, or an array of all flashdata + :rtype: mixed - :param mixed $newdata: Item name or array of items - :param mixed $newval: Item value or empty string (not required if $newdata is array) - :rtype: void + Gets the value for a specific ``$_SESSION`` item that has + been marked as "flashdata", or an array of all "flashdata" + items if no key was specified. + + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. You should + directly access ``$_SESSION`` instead. - Sets items into session example usages:: + .. method:: keep_flashdata($key) - $this->session->set_userdata('user', 'example@example.com'); - // adds item user with value example@example.com to the session + :param mixed $key: Flashdata key to keep, or an array of multiple keys + :returns TRUE on success, FALSE on failure + :rtype: bool - $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 + Retains the specified session data key(s) as "flashdata" + through the next request. - .. method:: unset_userdata($item) + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. It is just + an alias for the ``mark_as_flash()`` method. - :param mixed $item: Item name or an array containing multiple items - :rtype: void + .. method:: set_flashdata($data[, $value = NULL]) - Unsets previously set items from the session. Example:: + :param mixed $data: An array of key/value pairs to set as flashdata, or the key for a single item + :param mixed $value: The value to set for a specific session item, if $data is a key + :rtype: void - $this->session->unset_userdata('user'); - //unsets 'user' from session data. + Assigns data to the ``$_SESSION`` superglobal and marks it + as "flashdata". - $this->session->unset_userdata(array('user', 'useremail')); - //unsets both 'user' and 'useremail' from the session data. + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. - .. method:: has_userdata($item) + .. method:: mark_as_temp($key[, $ttl = 300]) - :param string $item: Item name - :returns: TRUE if item exists, FALSE if not + :param mixed $key: Key to mark as tempdata, or an array of multiple keys + :param int $ttl: Time-to-live value for the tempdata, in seconds + :returns: TRUE on success, FALSE on failure :rtype: bool - Checks if an item exists in the session. - - .. method:: flashdata([$item = NULL]) + Marks a ``$_SESSION`` item key (or multiple ones) as + "tempdata". - :param string $item: Flashdata item name - :returns: Item value if found, NULL if not or an array of all flashdata if $item parameter is not used - :rtype: mixed + .. method:: get_temp_keys() - If no parameter is passed, it will return an associative array of all existing flashdata. + :returns: Array containing the keys of all "tempdata" items. + :rtype: array - Otherwise returns a string containing the value of the passed item or NULL if the item is not found. - Example:: + Gets a list of all ``$_SESSION`` that have been marked as + "tempdata". - $this->session->flashdata('message'); - //returns 'Test message.' considering the set_flashdata example. + .. method:: umark_temp($key) - .. method:: set_flashdata($newdata[, $newval = '']) + :param mixed $key: Key to be un-marked as tempdata, or an array of multiple keys + :rtype: void - :param mixed $newdata: Item name or an array of items - :param mixed $newval: Item value or empty string (not required if $newdata is array) - :rtype: void + Unmarks a ``$_SESSION`` item key (or multiple ones) as + "tempdata". - Sets items into session flashdata example usages:: + .. method:: tempdata([$key = NULL]) - $this->session->set_flashdata('message', 'Test message.'); - // adds item 'message' with value 'Test message.' to the session flashdata + :param mixed $key: Tempdata item key or NULL + :returns: Value of the specified item key, or an array of all tempdata + :rtype: mixed - $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 + Gets the value for a specific ``$_SESSION`` item that has + been marked as "tempdata", or an array of all "tempdata" + items if no key was specified. + + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. You should + directly access ``$_SESSION`` instead. - .. method:: keep_flashdata($item) + .. method:: set_tempdata($data[, $value = NULL]) - :param mixed $item: Item name or an array containing multiple flashdata items + :param mixed $data: An array of key/value pairs to set as tempdata, or the key for a single item + :param mixed $value: The value to set for a specific session item, if $data is a key + :param int $ttl: Time-to-live value for the tempdata item(s), in seconds :rtype: void - Keeps items into flashdata for one more request. + Assigns data to the ``$_SESSION`` superglobal and marks it + as "tempdata". - .. method:: tempdata([$item = NULL]) + .. note:: This is a legacy method kept only for backwards + compatibility with older applications. - :param string $item: Tempdata item name - :returns: Item value if found, NULL if not or an array of all tempdata if $item parameter is not used - :rtype: mixed + .. method:: sess_regenerate([$destroy = FALSE]) - If no parameter is passed, it will return an associative array of all existing tempdata. + :param bool $destroy: Whether to destroy session data + :rtype: void - Otherwise returns a string containing the value of the passed item or NULL if the item is not found. - Example:: + Regenerate session ID, optionally destroying the current + session's data. - $this->session->tempdata('message'); - //returns 'Test message.' considering the set_tempdata example. + .. note:: This method is just an alias for PHP's native + `session_regenerate_id() + `_ function. - .. method:: set_tempdata($newdata[, $newval = ''[, $expire = 0]]) + .. method:: sess_destroy() - :param mixed $newdata: Item name or array containing multiple items - :param string $newval: Item value or empty string (not required if $newdata is array) - :param int $expire: Lifetime in seconds (0 for default) :rtype: void - Sets items into session tempdata example:: + Destroys the current session. - $this->session->set_tempdata('message', 'Test message.', '60'); - // adds item 'message' with value 'Test message.' to the session tempdata for 60 seconds + .. note:: This must be the *last* session-related function + that you call. All session data will be lost after + you do that. - $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 + .. note:: This method is just an alias for PHP's native + `session_destroy() + `_ function. - .. method:: unset_tempdata($item) + .. method:: __get($key) - :param mixed $item: Item name or an array containing multiple items - :rtype: void + :param string $key: Session item key + :returns: The requested session data item, or NULL if it doesn't exist + :rtype: mixed + + A magic method that allows you to use + ``$this->session->item`` instead of ``$_SESSION['item']``, + if that's what you prefer. + + It will also return the session ID by calling + ``session_id()`` if you try to access + ``$this->session->session_id``. + + .. method:: __set($key, $value) + + :param string $key: Session item key + :param mixed $value: Value to assign to the session item key + :returns: void - Unsets previously set items from tempdata. Example:: + A magic method that allows you to assign items to + ``$_SESSION`` by accessing them as ``$this->session`` + properties:: - $this->session->unset_tempdata('user'); - //unsets 'user' from tempdata. + $this->session->foo = 'bar'; - $this->session->unset_tempdata(array('user', 'useremail')); - //unsets both 'user' and 'useremail' from the tempdata. \ No newline at end of file + // Results in: + // $_SESSION['foo'] = 'bar'; \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 052c02fb042a307c689441ef32ef23e8451a3136 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 13:30:30 +0200 Subject: [ci skip] feature/session (#3073): Extend a note about DB drivers and locking --- user_guide_src/source/libraries/sessions.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 36b5415ac..3ca5aad17 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -581,10 +581,12 @@ also do the following, after creating the table:: ALTER TABLE ci_sessions ADD CONSTRAINT ci_sessions_id_ip UNIQUE (session_id, ip_address); .. important:: Only MySQL and PostgreSQL databases are officially - supported, due to lack of locking mechanisms on other platforms. - Using sessions without locks can cause all sorts of problems, - especially with heavy usage of AJAX, and we will not support - such cases. + supported, due to lack of advisory locking mechanisms on other + platforms. Using sessions without locks can cause all sorts of + problems, especially with heavy usage of AJAX, and we will not + support such cases. Use ``session_write_close()`` after you've + done processing session data if you're having performance + issues. Redis Driver ------------ -- cgit v1.2.3-24-g4f1b From 54e71b81d2cd1d0c9643f70d3d032b72c14ac574 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 13:57:05 +0200 Subject: [ci skip] feature/session: Update session lib doc title It's not a driver itself ... --- user_guide_src/source/libraries/sessions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 3ca5aad17..972c4001d 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -1,6 +1,6 @@ -############## -Session Driver -############## +############### +Session Library +############### The Session class permits you maintain a user's "state" and track their activity while they browse your site. -- cgit v1.2.3-24-g4f1b From 537242cdeb87c36dae998710032fb7b8aaf74692 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 14:37:27 +0200 Subject: [ci skip] feature/session (#3073): Update upgrade instructions --- user_guide_src/source/installation/upgrade_300.rst | 106 +++++++++++++++++---- 1 file changed, 85 insertions(+), 21 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index c84d16b31..3c6529a8b 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -83,37 +83,101 @@ or extensions to work, you need to move them to **application/core/**:: application/libraries/Log.php -> application/core/Log.php application/libraries/MY_Log.php -> application/core/MY_Log.php -********************************************************* -Step 6: Convert your Session usage from library to driver -********************************************************* +***************************************** +Step 6: Update your Session library usage +***************************************** -When you load (or autoload) the Session library, you must now load it as a driver instead of a library. This means -calling ``$this->load->driver('session')`` instead of ``$this->load->library('session')`` and/or listing 'session' -in ``$autoload['drivers']`` instead of ``$autoload['libraries']``. +The :doc:`Session Library ` has been completely +re-written in CodeIgniter 3 and now comes with a bunch of new features, +but that also means that there are changes that you should make ... -With the change from a single Session Library to the new Session Driver, two new config items have been added: +Most notably, - the library now uses separate storage drivers instead of +always relying on (encrypted) cookies. +In fact, cookies as storage have now been removed and you must always use +some kind of server-side storage engine, with the file-system being the +default option. - - ``$config['sess_driver']`` selects which driver to initially load. Options are: - - 'cookie' (the default) for classic CodeIgniter cookie-based sessions - - 'native' for native PHP Session support - - the name of a custom driver you have provided (see :doc:`Session Driver <../libraries/sessions>` for more info) - - ``$config['sess_valid_drivers']`` provides an array of additional custom drivers to make available for loading +The Session Class now utilizes PHP's own mechanisms for building custom +session handlers, which also means that your session data is now +accessible via the ``$_SESSION`` superglobal (though, we've kept the +possibility to use it as "userdata", like you've done until now). -As the new Session Driver library loads the classic Cookie driver by default and always makes 'cookie' and 'native' -available as valid drivers, neither of these configuration items are required. However, it is recommended that you -add them for clarity and ease of configuration in the future. +A few configuration options have been removed and a few have been added. +You should really read the whole :doc:`Session library manual +` for the details, but here's a short list of changes +that you should make: -If you have written a Session extension, you must move it into a 'Session' sub-directory of 'libraries', following the -standard for Drivers. Also beware that some functions which are not part of the external Session API have moved into -the drivers, so your extension may have to be broken down into separate library and driver class extensions. + - Set your ``$config['sess_driver']`` value + + It will default to 'files', unles you've previously used + ``$config['sess_use_database']``, in which case it will be set to + 'database'. + + - Set a ``$config['sess_save_path']`` value + + For the 'database' driver, a fallback to ``$config['sess_table_name']`` + is in place, but otherwise requires you to read the manual for the + specific driver of your choice. + + - Update your ``ci_sessions`` table ('database' driver only) + + The table structure has changed a bit, and more specifically: + + - ``user_agent`` field is dropped + - ``user_data`` field is renamed to ``data`` and under MySQL is now of type BLOB + - ``last_activity`` field is renamed to ``timestamp`` + + This is accompanied by a slight change in the table indexes too, so + please read the manual about the :doc:`Session Database Driver + ` for more information. + + .. important:: Only MySQL and PostgreSQL are officially supported + now. Other databases may still work, but due to lack of advisory + locking features, they are unsafe for concurrent requests and + you should consider using another driver instead. + + - Remove ``$config['sess_match_useragent']`` + + The user-agent string is input supplied by the user's browser, or in + other words: client side input. As such, it is an ineffective feature + and hence why it has been removed. + + - Remove ``$config['sess_encrypt_cookie']`` + + As already noted, the library no longer uses cookies as a storage + mechanism, which renders this option useless. + + - Remove ``$config['sess_expire_on_close']`` + + This option is still usable, but only for backwards compatibility + purposes and it should be otherwise removed. The same effect is + achieved by setting ``$config['sess_expiration']`` to 0. + + - Check "flashdata" for collisions with "userdata" + + Flashdata is now just regular "userdata", only marked for deletion on + the next request. In other words: you can't have both "userdata" and + "flashdata" with the same name, because it's the same thing. + + - Check usage of session metadata + + Previously, you could access the 'session_id', 'ip_address', + 'user_agent' and 'last_activity' metadata items as userdata. + This is no longer possible, and you should read the notes about + :doc:`Session Metadata ` if your + application relies on those values. + +Finally, if you have written a Session extension, you must now move it to +the *application/libraries/Session/* directory, although chances are that +it will now also have to be re-factored. *************************************** Step 7: Update your config/database.php *************************************** -Due to 3.0.0's renaming of Active Record to Query Builder, inside your `config/database.php`, you will -need to rename the `$active_record` variable to `$query_builder` -:: +Due to 3.0.0's renaming of Active Record to Query Builder, inside your +**config/database.php**, you will need to rename the ``$active_record`` +variable to ``$query_builder``:: $active_group = 'default'; // $active_record = TRUE; -- cgit v1.2.3-24-g4f1b From e3d66af0845c0b9f995d1890d890cfd36ce1f3fc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 14:51:37 +0200 Subject: [ci skip] Fix a typo in Card library docs --- user_guide_src/source/libraries/cart.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/libraries/cart.rst b/user_guide_src/source/libraries/cart.rst index a023ccb36..3c0a79178 100644 --- a/user_guide_src/source/libraries/cart.rst +++ b/user_guide_src/source/libraries/cart.rst @@ -7,7 +7,7 @@ while a user is browsing your site. These items can be retrieved and displayed in a standard "shopping cart" format, allowing the user to update the quantity or remove items from the cart. -.. important:: The Card library is DEPRECATED and should not be used. +.. important:: The Cart library is DEPRECATED and should not be used. It is currently only kept for backwards compatibility. Please note that the Cart Class ONLY provides the core "cart" -- cgit v1.2.3-24-g4f1b From 9a0e66096a1d70c28a7d5358f966f936f609d52b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 14:54:08 +0200 Subject: [ci skip] Manually apply PR #3461 I would've merged it earlier, but that would cause conflicts when feature/session is merged. --- user_guide_src/source/libraries/sessions.rst | 4 ++-- user_guide_src/source/libraries/trackback.rst | 2 +- user_guide_src/source/libraries/zip.rst | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 972c4001d..be1a39ef2 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -404,8 +404,8 @@ Preference Default Options **sess_expiration** 7200 (2 hours) Time in seconds (integer) The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0 **sess_save_path** NULL None Specifies the storage location, depends on the driver being used. -**sess_time_to_update** 300 Time in seconds (integer) This options controls how often the session class will regenerate itself and create a new - session ID. Setting it to 0 will disable session ID regeneartion. +**sess_time_to_update** 300 Time in seconds (integer) This option controls how often the session class will regenerate itself and create a new + session ID. Setting it to 0 will disable session ID regeneration. **sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to validate the user's IP address when reading the session cookie. Note that some ISPs dynamically changes the IP, so if you want a non-expiring session you will likely set this to FALSE. diff --git a/user_guide_src/source/libraries/trackback.rst b/user_guide_src/source/libraries/trackback.rst index 22859a13d..da7c319ac 100644 --- a/user_guide_src/source/libraries/trackback.rst +++ b/user_guide_src/source/libraries/trackback.rst @@ -67,7 +67,7 @@ Description of array data: - **blog_name** - The name of your weblog. - **charset** - The character encoding your weblog is written in. If omitted, UTF-8 will be used. -.. note:: the Trackback class will automatically send only the first 500 characters of your +.. note:: The Trackback class will automatically send only the first 500 characters of your entry. It will also strip all HTML. The Trackback sending method returns TRUE/FALSE (boolean) on success diff --git a/user_guide_src/source/libraries/zip.rst b/user_guide_src/source/libraries/zip.rst index b509236de..ce70e6c88 100644 --- a/user_guide_src/source/libraries/zip.rst +++ b/user_guide_src/source/libraries/zip.rst @@ -2,9 +2,8 @@ Zip Encoding Class ################## -CodeIgniter's Zip Encoding Class classes permit you to create Zip -archives. Archives can be downloaded to your desktop or saved to a -directory. +CodeIgniter's Zip Encoding Class permits you to create Zip archives. +Archives can be downloaded to your desktop or saved to a directory. .. contents:: :local: -- cgit v1.2.3-24-g4f1b From 3fd1c270ef8a6e59baec4ca59191a0a0ea796e35 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 15:35:52 +0200 Subject: [ci skip] Update changelog messages for Session library --- user_guide_src/source/changelog.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 8b4f4039e..7211210d7 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -283,19 +283,19 @@ Release Date: Not Released - :doc:`Session Library ` changes include: - - Library changed to :doc:`Driver ` with classic 'cookie' driver as the default. - - Added a 'native' PHP Session driver to work with ``$_SESSION``. - - Added a new **tempdata** feature that allows setting userdata items with expiration time (``tempdata()``, ``set_tempdata()``, ``unset_tempdata()``). - - Added default ``$config['sess_driver']`` and ``$config['sess_valid_drivers']`` items to *application/config.php* file. - - Changed 'cookie' driver to respect php.ini's *session.gc_probability* and *session.gc_divisor* settings. - - Changed 'cookie' driver to use HMAC authentication instead of a simple md5 checksum. - - Changed 'cookie' driver to select only one row when using database sessions. - - Changed 'cookie' driver to write to only write to the database at end of page execution. + - Completely re-written the library to use self-contained drivers via ``$config['sess_driver']``. + - Added 'files', 'database', 'redis' and 'memcached' drivers (using 'files' by default). + - Added ``$config['sess_save_path']`` setting to specify where the session data is stored, depending on the driver. + - Dropped support for storing session data in cookies (which renders ``$config['sess_encrypt_cookie']`` useless and is therefore also removed). + - Dropped official support for storing session data in databases other than MySQL and PostgreSQL. + - Changed table structure for the 'database' driver. + - Added a new **tempdata** feature that allows setting userdata items with expiration time (``mark_as_temp()``, ``tempdata()``, ``set_tempdata()``, ``unset_tempdata()``). - Changed method ``keep_flashdata()`` to also accept an array of keys. - Changed methods ``userdata()``, ``flashdata()`` to return an array of all userdata/flashdata when no parameter is passed. - Deprecated method ``all_userdata()`` - it is now just an alias for ``userdata()`` with no parameters. - Added method ``has_userdata()`` that verifies the existence of a userdata item. - Added *debug* level log messages for key events in the session validation process. + - Dropped support for the *sess_match_useragent* option. - :doc:`File Uploading Library ` changes include: -- cgit v1.2.3-24-g4f1b From d8e25e94583706b02e0d39f7c108f4fb7ced656d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 19 Jan 2015 22:03:57 +0200 Subject: [ci skip] Some polishing to the latest doc changes --- user_guide_src/source/installation/upgrade_300.rst | 6 +++--- user_guide_src/source/libraries/sessions.rst | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 3c6529a8b..24353b35f 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -91,7 +91,7 @@ The :doc:`Session Library ` has been completely re-written in CodeIgniter 3 and now comes with a bunch of new features, but that also means that there are changes that you should make ... -Most notably, - the library now uses separate storage drivers instead of +Most notably, the library now uses separate storage drivers instead of always relying on (encrypted) cookies. In fact, cookies as storage have now been removed and you must always use some kind of server-side storage engine, with the file-system being the @@ -164,8 +164,8 @@ that you should make: Previously, you could access the 'session_id', 'ip_address', 'user_agent' and 'last_activity' metadata items as userdata. This is no longer possible, and you should read the notes about - :doc:`Session Metadata ` if your - application relies on those values. + :doc:`Session Metadata ` + if your application relies on those values. Finally, if you have written a Session extension, you must now move it to the *application/libraries/Session/* directory, although chances are that diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index be1a39ef2..18433d1ac 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -378,7 +378,7 @@ by default: 'session_id', 'ip_address', 'user_agent', 'last_activity'. This was due to the specifics of how sessions worked, but is now no longer necessary with our new implementation. However, it may happen that your application relied on these values, so here are alternative methods of -accessing them:: +accessing them: - session_id: ``session_id()`` - ip_address: ``$_SERVER['REMOTE_ADDR']`` -- cgit v1.2.3-24-g4f1b From a2dee7dab707a25e4a2a1cec1c2bfcf615d2272d Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 20 Jan 2015 04:22:29 +0100 Subject: Fix Sphinx compilation errors --- user_guide_src/source/installation/upgrade_220.rst | 2 +- user_guide_src/source/installation/upgrade_300.rst | 10 +++++----- user_guide_src/source/installation/upgrading.rst | 3 ++- user_guide_src/source/libraries/sessions.rst | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/installation/upgrade_220.rst b/user_guide_src/source/installation/upgrade_220.rst index beb7bd7d7..b2e943223 100644 --- a/user_guide_src/source/installation/upgrade_220.rst +++ b/user_guide_src/source/installation/upgrade_220.rst @@ -2,7 +2,7 @@ Upgrading from 2.1.4 to 2.2.0 ############################# -.. note:: The :doc:`Encrypt Class ` now requires the +.. note:: The :doc:`Encrypt Class ` now requires the Mcrypt extension. If you were previously using the Encrypt Class without Mcrypt, then this is a breaking change. You must install the Mcrypt extension in order to upgrade. For information on diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 24353b35f..3e6db390e 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -87,7 +87,7 @@ or extensions to work, you need to move them to **application/core/**:: Step 6: Update your Session library usage ***************************************** -The :doc:`Session Library ` has been completely +The :doc:`Session Library ` has been completely re-written in CodeIgniter 3 and now comes with a bunch of new features, but that also means that there are changes that you should make ... @@ -104,7 +104,7 @@ possibility to use it as "userdata", like you've done until now). A few configuration options have been removed and a few have been added. You should really read the whole :doc:`Session library manual -` for the details, but here's a short list of changes +` for the details, but here's a short list of changes that you should make: - Set your ``$config['sess_driver']`` value @@ -128,8 +128,8 @@ that you should make: - ``last_activity`` field is renamed to ``timestamp`` This is accompanied by a slight change in the table indexes too, so - please read the manual about the :doc:`Session Database Driver - ` for more information. + please read the manual about the `Session Database Driver + <../libraries/sessions.html#database-driver>`_ for more information. .. important:: Only MySQL and PostgreSQL are officially supported now. Other databases may still work, but due to lack of advisory @@ -164,7 +164,7 @@ that you should make: Previously, you could access the 'session_id', 'ip_address', 'user_agent' and 'last_activity' metadata items as userdata. This is no longer possible, and you should read the notes about - :doc:`Session Metadata ` + `Session Metadata <../libraries/sessions.html#accessing-session-metadata>`_ if your application relies on those values. Finally, if you have written a Session extension, you must now move it to diff --git a/user_guide_src/source/installation/upgrading.rst b/user_guide_src/source/installation/upgrading.rst index 366aa13f7..5b98ea46d 100644 --- a/user_guide_src/source/installation/upgrading.rst +++ b/user_guide_src/source/installation/upgrading.rst @@ -8,7 +8,8 @@ upgrading from. .. toctree:: :titlesonly: - Upgrading from 2.1.4 to 3.0.0 + Upgrading from 2.2.0 to 3.0.0 + Upgrading from 2.1.4 to 2.2.0 Upgrading from 2.1.3 to 2.1.4 Upgrading from 2.1.2 to 2.1.3 Upgrading from 2.1.1 to 2.1.2 diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 18433d1ac..af8c1a8d2 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -47,7 +47,7 @@ Once loaded, the Sessions library object will be available using:: $this->session -.. important:: Because the :doc:`Loader Class <../loader>` is instantiated +.. important:: Because the :doc:`Loader Class ` is instantiated by CodeIgniter's base controller, make sure to call ``parent::__construct()`` before trying to load a library from inside a controller constructor. @@ -400,7 +400,7 @@ You'll find the following Session related preferences in your Preference Default Options Description ======================== =============== ======================================== ============================================================================================ **sess_driver** files files/database/redis/memcached/*custom* The session storage driver to use. -**sess_cookie_name** ci_session [A-Za-z_-] characters only The name used for the session cookie. +**sess_cookie_name** ci_session [A-Za-z\_-] characters only The name used for the session cookie. **sess_expiration** 7200 (2 hours) Time in seconds (integer) The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0 **sess_save_path** NULL None Specifies the storage location, depends on the driver being used. @@ -878,7 +878,7 @@ Class Reference .. method:: keep_flashdata($key) :param mixed $key: Flashdata key to keep, or an array of multiple keys - :returns TRUE on success, FALSE on failure + :returns: TRUE on success, FALSE on failure :rtype: bool Retains the specified session data key(s) as "flashdata" -- cgit v1.2.3-24-g4f1b From 90726b8c769ea75aec34814ddfa91655d488e6c3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 12:39:22 +0200 Subject: [ci skip] Change some log messages' level 'Class Loaded' type of messages flood log files when log_threshold is set to 2 (debug). They're now logged as 'info' level. This is manually applying PR #1528, which was created to do the same thing, but became outdated. --- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/general/errors.rst | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 73a183b6c..2a61dd2bd 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -58,6 +58,7 @@ Release Date: Not Released - Added support for turning newline standardization on/off via ``$config['standardize_newlines']`` and set it to FALSE by default. - Added configuration setting ``$config['composer_autoload']`` to enable loading of a `Composer `_ auto-loader. - Removed the automatic conversion of 'programmatic characters' to HTML entities from the :doc:`URI Library `. + - Changed log messages that say a class or file was loaded to "info" level instead of "debug", so that they don't pollute log files when ``$config['log_threshold']`` is set to 2 (debug). - Helpers diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 26c26bea1..721c78ca7 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -101,9 +101,7 @@ There are three message types: example, if a class has been initialized, you could log this as debugging info. #. Informational Messages. These are the lowest priority messages, - simply giving information regarding some process. CodeIgniter doesn't - natively generate any info messages but you may want to in your - application. + simply giving information regarding some process. .. note:: In order for the log file to actually be written, the *logs* directory must be writable. In addition, you must set the "threshold" -- cgit v1.2.3-24-g4f1b From 0da50123c196ca0f342cac44b76f889a6f8a96b9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 13:30:05 +0200 Subject: Pagination: Add 'use_global_url_suffix' setting Resolves issue #1887 --- user_guide_src/source/changelog.rst | 3 ++- user_guide_src/source/libraries/pagination.rst | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 2a61dd2bd..aace0281f 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -396,9 +396,10 @@ Release Date: Not Released - Added support for the anchor "rel" attribute. - Added support for setting custom attributes. - Added support for language translations of the *first_link*, *next_link*, *prev_link* and *last_link* values. + - Added support for ``$config['num_links'] = 0`` configuration. - Added ``$config['reuse_query_string']`` to allow automatic repopulation of query string arguments, combined with normal URI segments. + - Added ``$config['use_global_url_suffix']`` to allow overriding the library 'suffix' value with that of the global ``$config['url_suffix']`` setting. - Removed the default `` `` from a number of the configuration variables. - - Added support for ``$config['num_links'] = 0`` configuration. - :doc:`Profiler Library ` changes include: diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst index 8c5c2c63a..d51d0dd27 100644 --- a/user_guide_src/source/libraries/pagination.rst +++ b/user_guide_src/source/libraries/pagination.rst @@ -131,6 +131,12 @@ the offset segment. A custom suffix added to the path. The sufix value will be right after the offset segment. +**$config['use_global_url_suffix'] = FALSE;** + +When set to TRUE, it will **override** the ``$config['suffix']`` value and +instead set it to the one that you have in ``$config['url_suffix']`` in +your **application/config/config.php** file. + *********************** Adding Enclosing Markup *********************** -- cgit v1.2.3-24-g4f1b From 2c245616a7bc89e842b4f39693751c3d28c034f2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 20 Jan 2015 15:40:27 +0200 Subject: Revert 7c4d10660a0a47446474bf97e3cb65f80693f1ee Deprecates form_prep() in favor of html_escape() (again). Related: issue #1953, which was the reason for the reverted commit, but was wrongly interpreted and that shouldn't have happened. Close #2477 --- user_guide_src/source/changelog.rst | 2 +- user_guide_src/source/helpers/form_helper.rst | 85 +++++++++++++--------- user_guide_src/source/installation/upgrade_300.rst | 12 +++ 3 files changed, 65 insertions(+), 34 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index aace0281f..e389d0a49 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -104,7 +104,7 @@ Release Date: Not Released - :doc:`Form Helper ` changes include: - :func:`form_dropdown()` will now also take an array for unity with other form helpers. - - :func:`form_prep()`'s second argument now only accepts a boolean value, which determines whether the value is escaped for a