http://www.perlmonks.org?node_id=606990

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on What is Difference between Session and Cookie

Replies are listed 'Best First'.
Re: What is Difference between Session and Cookie
by marto (Cardinal) on Mar 28, 2007 at 12:01 UTC
      The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. A cookie can keep information in the user's browser until deleted. Sessions work instead like a token allowing access and passing information while the user has their browser open. The problem with sessions is that when you close your browser you also lose the session. I have read the very good post on cookies and sessions with suitable php code.You can see that in http://cs-pages.blogspot.com/2011/05/difference-between-cookies-and-sessions.html
        The problem with sessions is that when you close your browser you also lose the session.

        That is not a property of sessions.

        If closing your browser deletes cookies, and deletes the session cookie, then there is nothing associating your browser and the session, and the session can be considered lost.

        If however, a session is also associated with an account, breaking the association with the browser (deleting cookies) doesn't break the association with the account -- you can resume the session after you log-in again

      Martin's answer is more self-serving than informative since the definitional difference between cookies and sessions are congruent among all languages.
Re: What is Difference between Session and Cookie
by davorg (Chancellor) on Mar 28, 2007 at 12:04 UTC
Re: What is Difference between Session and Cookie
by ikegami (Patriarch) on Mar 28, 2007 at 12:45 UTC

    A session is a store of data on the server containing state information on a user. A particular sessions is identified by its session id, ideally a large (i.e. unguessable) random number. For example, the session could hold a user's shopping cart.

    A cookie is also a store. To create a cookie, the server sends a HTTP header to the client (i.e. the web browser). If the client supports and accepts the cookie, the cookie will be sent back to the server along with every request made to the server.

    Cookies are often used to store a session id, binding the session to the user.

Re: What is Difference between Session and Cookie
by Ojosh!ro (Beadle) on Mar 28, 2007 at 13:03 UTC
    Sessions and cookies

    No doubt you found the term ,,cookie'' appear frequently when ,,sessions'' are being discussed.
    A cookie is a bit of information which is sent to your browser and stored there. The browser will send this information back to the server every time you send a request. (to the server that set the cookie)
    This behaviour can be used to identify a session if sessions take more than one (server-(client)-server) transactions.
    Hmmm, analogy?
    Imagine the webapplication as a fairground (carnival?). You pay for a ticket when you enter (start a session). The ticket now is your cookie and every ride (transaction) you want to go on you wave your ticket (cookie) and get on it. Without a cookie you would have to buy a ticket for every single ride.

    if( exists $aeons{strange} ){ die $death unless ( $death%2 ) }
Re: What is Difference between Session and Cookie
by j3 (Friar) on Mar 28, 2007 at 14:48 UTC

    Remember, HTTP is a stateless protocol. Without adding any extra magic, if a user visits your site twice in a row, as far as the web server is concerned, those are two totally separate visits having nothing in common with eachother (save for coming from the same IP address).

    If you want your web server to be able to remember users between pages they visit, you need some way to create a "session" -- some way to save information about the user so you can recognize them the next time they request a page.

    The most common way to do this is by using cookies.

    So, sessions are what you want, and cookies are most often how you get them.

      save for coming from the same IP address

      Sometimes, not even that. Some people use load-balanced proxies, so requests don't always come from the same IP address. I believe AOL does this.