Welcome Guest, Not a member yet? Register   Sign In
Why uses Code Ignitor cookies for sessions?


I would like to know why CI uses cookies for sessions. I saw that there are also libraries to emulate $_SESSION with a database. I do not understand why CI does not base it's class on the default php session ($_SESSION).


[eluser]Eric Cope[/eluser]
PHP sessions use cookies too (or GET variables like sid). Its the only way get the state from the browser. CI does not use PHP sessions due to server installation differences. Its mentioned in the CI documentation.

A PHP session solves this problem by allowing you to store user information on the server for later use (i.e. username, shopping items, etc). However, session information is temporary and will be deleted after the user has left the website. If you need a permanent storage you may want to store the data in a database.
from http://www.w3schools.com/PHP/php_sessions.asp.

So, if I understand it well, it does not store it as cookie, but in the server. By using a database, when PHP restarts (or an other condition occurs), the session variables are not lost. So your statement is false, if you meant that the cookies where in the client side.

Thanks for your reply.

[eluser]Eric Cope[/eluser]
The data is stored server-side. But a session id must be stored on the client side, otherwise there is no way for the server to know the difference between to clients. The session id is either stored in a cookie or in a GET variable.

CI (as of 1.7) stores data in a cookie or database depending on your settings. It still stores a session id in a cookie, for the same reason above.

[eluser]Colin Williams[/eluser]
Even native PHP session handling uses a cookie if not a query string param. You have to have the session id hash somewhere on the client side.

Thanks for your replies, you where very helpfulWink

Theme © iAndrew 2016 - Forum software by © MyBB