Welcome Guest, Not a member yet? Register   Sign In
Using $_SESSION vs $this->session
#4

(09-30-2016, 06:52 PM)daveĀ friend Wrote: If you don't use CI_Session then you will have to write your own code managing PHP sessions. $_SESSION isn't available until some code in your app makes a call to PHP's session_start(). Why reinvent the wheel?

CI versions > 3.0.x manage PHP sessions quite well and add some handy additional functionality. CI sessions can be autoloaded by using CI's autoload.php config file removing the need to load the library in multiple controllers. Although loading the library only where needed doesn't involve a lot of work either.

Most of the setting and retrieval of session data in the session library (version >= 3.0.0) is working directly with the $_SESSION variable. The retrieval functions $this->session->item and $this->session->userdata('item') have an advantage over $_SESSION['item'] in that the class functions return NULL if the item does not exist in the $_SESSION array. Directly reading from $_SESSION means you need to make sure the item exists before trying to access the array. Now that gets tedious.

The advantage of using a framework like CI is that a lot of that kind of tedium is eliminated. Why not use what the framework provides?


Thanks for your detailed reply. It helped clarify the advantages of using the CI session class.
Reply


Messages In This Thread
Using $_SESSION vs $this->session - by Cannondale - 09-30-2016, 03:18 PM
RE: Using $_SESSION vs $this->session - by Cannondale - 10-01-2016, 03:42 AM
RE: Using $_SESSION vs $this->session - by Narf - 10-03-2016, 12:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB