CodeIgniter Forums
Problems with the native session - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Problems with the native session (/showthread.php?tid=18840)

Pages: 1 2

Problems with the native session - El Forum - 05-20-2009

[eluser]Thorpe Obazee[/eluser]

Problems with the native session - El Forum - 05-21-2009

I think you're going to have problems using CodeIgniter sessions and native sessions. I seem to recall the two don't play nicely together. The CodeIgniter session class uses session_start(), so calling it a second time shouldn't be necessary. I'd suggest that you use a version of the session library that made for working with native sessions only -

Problems with the native session - El Forum - 05-22-2009

Yes that was the problem, i am so silly... I am nearly done with the project and i am using only the native session, i am still beginner with CI, so i still rely on php native stuff. But on my next project i will take in consideration using CI Session library. Thank you all for being helpful, i appreciate it. I was stuck for months trying to learn CakePHP and all i was getting was nights without sleep and trying to figure out how things work. Using CI i learned a lot about php itself, i am using the user guide and learning from the core code as well. When i have time i will do a translation of CI documentation in Macedonian. Thanks again guys, i really didn't expect so many answers.Smile

Problems with the native session - El Forum - 05-23-2009

The CI session library couldn't be any easier if it tried.
$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:
$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:

$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:

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

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

Problems with the native session - El Forum - 05-23-2009

[quote author="bargainph" date="1242891772"]<snipped>[/quote]

Aw, poor doggy...