Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is the difference between session and cookie?give one example of each ?

user-image
Question ajoutée par Mohammad Irfan , Certified Magento Developer , Xcite.com
Date de publication: 2013/10/09
Samuel Eid Safwat Naguib
par Samuel Eid Safwat Naguib , Technology lead ,Project Manager ,Transformation Coach , Octalpha

Cookie: A key/value pair that is stored by the user's browser and is available in the superglobal $_COOKIE array available in PHP. The cookie request is initiated with an explicitly defined expiration date. For example:

setcookie('cookieName', $some_value, time()+3600, "/", ".example.com")

On the next server request, $_COOKIE['cookieName'] will be available. If you use a browser tool to look at the cookie, it will have an expiration date.

Session Cookie: Identical to the above but defined without an expiration date. If you use the same browser tool it will say that the cookie expires at the end of the session; which is ultimately when you close your browser. For example:

setcookie('cookieName', $some_value);

PHP Session: a server side mechanism that will associate a bunch of data with a session id. Every time a session is invoked, it serializes/unserializes it. This could be more data than just a single key/value pair that a cookie supports, but the way of associating this data with a user is by creating a cookie (regular or session as described above) in their browser that contains the session id. This way, the right data can be retrieved for a given user based on the value of that cookie.

Mostafa Hashem
par Mostafa Hashem , Functional consultant / Solution Architect , international turnkey system (its)

1- Session stored Server side, however cookie is stored client side

2- Session is created and maintained by the web server or application server, however is created and maintained by the developer

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?