tags:

views:

150

answers:

3
+3  Q: 

How cookies work?

I wanted to know the interactions of a browser (i.e. Firefox ) and a website.

When I submit my user name and password to the login form, what happens? I think that website sends me some cookies and authorizes me by checking those cookies.

Is there a standard structure for cookies?

Update:

Also, how I can see the cookies of specific URL sent to my browser if I want to use that cookie?

+5  A: 

Hai safaali,

Understanding Cookies

Cookies are given to a browser by the server. The browser reveals the cookies as applicable only to the domain that provided the cookie in the first place.

The data in the cookie allows the server to continue a conversation, so to speak. Without the cookie, the server considers the browser a first-time visitor.

Have a look at these to know about browser cookies

Understanding Browser cookies

http://internet-security.suite101.com/article.cfm/understanding_computer_browser_cookies

http://www.willmaster.com/library/cookies/understanding-cookies.php

http://articles.techrepublic.com.com/5100-22_11-6063884.html

Pandiya Chendur
You may also care to read the actual RFC: http://www.ietf.org/rfc/rfc2109.txt
AJ
+1  A: 

It depends, because there are many scenarios and abilities of usage of cookies.

One of scenarios is:

  1. User submits login form.
  2. Website authorizes the user and set cookie visible in website domain with user name, password (i.e. MD5 hashed) and sometimes other information.
  3. Cookie is sent with each request, which allows website to check if request is came from the authorized user.

For more details read Wikipedia article about cookies.

Grzegorz Gierlik
@Peter -- thanks for edit.
Grzegorz Gierlik
A: 

Usually the cookie contains a session id number. The id number is then connected to session data that is stored on the server. The usual process is then:

  1. Send login form
  2. Server checks username and password
  3. If correct, the username is stored in a session file on the server, along with various other useful information about the user (if it's a site admin, moderator, userid and so on).
  4. The server sends back a cookie containing an id number that identifies the session file
  5. The browser sends the cookie with each request to that server, so the server can open the session file and read the saved data.

Usually the password is not sent more than once (at login in step 1).

Emil Vikström
You can have cookies without sessions. In fact, it's specifically called a 'session cookie'.
Jacob Relkin