Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

What is Difference between Session and Cookie

by Anonymous Monk
on Mar 28, 2007 at 11:57 UTC ( #606990=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi Greatmonks
wht is Difference between Session and Cookie ? where we can get more info

Comment on What is Difference between Session and Cookie
Re: What is Difference between Session and Cookie
by marto (Bishop) on Mar 28, 2007 at 12:01 UTC
      Martin's answer is more self-serving than informative since the definitional difference between cookies and sessions are congruent among all languages.
      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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://606990]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-12-29 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (192 votes), past polls