• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why uses Code Ignitor cookies for sessions?

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

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

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

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.