Mirza Hassam
Mirza Hassam

Reputation: 43

Working with Sessions and Cookies

I have this one question in mind that in login sessions does client have to maintain anything so that server uniquely identify client and in multiple client requests response to correct client. I don't understand this sessions and cookies. I asked many about this some say that its server job to maintain sessions and client just send normal request.

Upvotes: 0

Views: 80

Answers (3)

Matthew Flaschen
Matthew Flaschen

Reputation: 284927

Yes, the client must keep track of something, called a session ID. Most commonly, it is a cookie. However, a less used approach is to rewrite all links to pass the session ID in the URL.

Example ID names are ASP.NET_SessionId and PHPSESSID.

Upvotes: 1

Ramesh PVK
Ramesh PVK

Reputation: 15446

It is the server which will maintain the sessions. And it is the server responsibilty to allow session tracking happen. Clients need not bother about sending any information explicitly. As Cliens also sends Cookies saved on the client along with every request, server might use Cookies for sesssion tracking.

Note: Cookies are just one of the way to implement Session Tracking. It is also the best way

So server Cookies as one of the ways to handle session tracking.

It can also be done in other ways:

  • URL rewriting - the application/server should append the session id in all URL's/Links. When those are invoked from the client the session comes to the server along with the URL.
  • Hidden Form Fields - The forms may contain hidden input type with session id as field value. When the form is posted, the session id comes along with the form data.

Upvotes: 0

Adam McKee
Adam McKee

Reputation: 204

Matthew's answer is correct.

It is the server's job to keep track of login sessions, and it's the client web browser's job to keep track of cookies. When you provide username & password on a site, a cookie is provided by the web server to your browser, which will automatically be provided along with subsequent requests to the web server. This cookie uniquely identifies a session which belongs to a particular user on the site (even the "guest" user). So, the server keeps track of all client sessions, and each client remembers its session cookie & provides it along with all its requests. It's a simple scheme. Using Firebug for example, you can see what the web requests look like when you log into a site. You might find that interesting to look at.

Upvotes: 0

Related Questions