Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

when to use cookies and when to use session?

Status
Not open for further replies.

hxx

Technical User
Oct 26, 2000
10
MY
When is it more suitable to use cookies and session? Does it has any paritcular effect, whichever is used?
 
If you have a web farm, you can't use session variables, since they are bound to a particular web server. Also, session variables take up memory on the server.

Cookies can be used to save information from one session to the next, which session variables can't. However, cookies have limitations too. Each domain is restricted to 20 cookies, and each cookie has a 4k size limit.

A lot depends on the type of application you have, and also the amount of traffic.


nick bulka

 
Correct me if I am wrong, but don't session objects also use client-side cookies? I think the bigger question is why use Session Objects at all? If you absolutely need to store state information than it should be stored as either a cookie or even better in a Server-side DB. Then you don't have to worry about those browser people that turn cookies off.


Wushutwist


Sun Certified Java 2 Programmer
 
The session objet uses cookies to store the Session ID rather than the data on the client machine.
Nick is right - you do need to use cookies when load-balancing, and also if your Server has stability problems then cookies are a better option than the session variable.

As a general rule, cookies are good for saving state across sessions, or when using load balancing. Session variables are good for single session use on a stable machine under acceptable load.

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top