CodeIgniter Forums
Why uses Code Ignitor cookies for sessions? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why uses Code Ignitor cookies for sessions? (/showthread.php?tid=14602)



Why uses Code Ignitor cookies for sessions? - El Forum - 01-08-2009

[eluser]doktorcivanim[/eluser]
Hi,

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).

Thanks.


Why uses Code Ignitor cookies for sessions? - El Forum - 01-08-2009

[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.


Why uses Code Ignitor cookies for sessions? - El Forum - 01-08-2009

[eluser]doktorcivanim[/eluser]
Code:
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.


Why uses Code Ignitor cookies for sessions? - El Forum - 01-08-2009

[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.


Why uses Code Ignitor cookies for sessions? - El Forum - 01-08-2009

[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.


Why uses Code Ignitor cookies for sessions? - El Forum - 01-09-2009

[eluser]doktorcivanim[/eluser]
Thanks for your replies, you where very helpfulWink