Welcome Guest, Not a member yet? Register   Sign In
Problems with the native session
#14

[eluser]TheFuzzy0ne[/eluser]
The CI session library couldn't be any easier if it tried.
Code:
$this->session->set_userdata('some_key', 'some_value'); # Sets userdata.
$this->session->userdata('some_key'); # Returns the userdata wih the specified key.
$this->session->unset_userdata('some_key'); # Unsets the userdata.
$this->session->all_userdata(); # Retrieves the entire userdata array.

That's pretty much all you need to know. Then there's flashdata:
Code:
$this->session->set_flashdata('some_key', 'some_value'); # Set data to be available on the next request only.
$this->session->keep_flashdata('some_key'); # Extends the lifespan by one request.

The library has been made to make things easier for you. One of the best things I love about this, is that I can do something like this:

Code:
$data = $this->session->userdata('value_that_doesnt_exist');

And if it doesn't exist, FALSE will be returned. Doing the same thing with native sessions would result in a PHP notice unless you did this:

Code:
$data = (isset($_SESSION['value_that_doesnt_exist']) ? $_SESSION['value_that_doesnt_exist'] : FALSE;

I think it's clear which one is better here. Smile


Messages In This Thread
Problems with the native session - by El Forum - 05-20-2009, 05:15 AM
Problems with the native session - by El Forum - 05-20-2009, 05:19 AM
Problems with the native session - by El Forum - 05-20-2009, 05:38 AM
Problems with the native session - by El Forum - 05-20-2009, 05:47 AM
Problems with the native session - by El Forum - 05-20-2009, 05:49 AM
Problems with the native session - by El Forum - 05-20-2009, 06:50 AM
Problems with the native session - by El Forum - 05-20-2009, 10:01 AM
Problems with the native session - by El Forum - 05-20-2009, 01:32 PM
Problems with the native session - by El Forum - 05-20-2009, 03:18 PM
Problems with the native session - by El Forum - 05-20-2009, 08:40 PM
Problems with the native session - by El Forum - 05-20-2009, 08:42 PM
Problems with the native session - by El Forum - 05-21-2009, 02:04 AM
Problems with the native session - by El Forum - 05-22-2009, 09:46 PM
Problems with the native session - by El Forum - 05-23-2009, 04:58 AM
Problems with the native session - by El Forum - 05-23-2009, 04:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB