session cookie vs. regular cookie

M

Matt

I want to know what's the differences between session cookie and regular
cookie.

In ASP, when we create cookie, we do the following to identify an user:

Response.Cookies("name") = value

Is this regular cookie? How about session cookie? and when to use which?
 
B

Blair Bonnett

What you are using is a regular cookie. All the data is stored on the users
computer. Each time the user loads a page on your site, their browser sends
all the cookie data set by your domain to the server (accessible through
the Request.Cookies collection). When you request their username, using
strUsername = Request.Cookies("name"), the server finds the appropriate
value from all the cookie data sent by the browser, and returns it to the
application. See http://www.w3schools.com/asp/asp_cookies.asp for further
information.

A session cookie is one where all the data is stored on the server (through
the Session object). The only thing stored on the clients computer is an ID
string, so the server knows which user to set / retrieve values for. They
can be set / retrieved using the following code:
Session("name") = strUsername
strUsername = Session("name")

The disadvantage of this is that it takes up server power. It is
recommended that you use it sparingly; regular cookies are best for almost
every situation. A good example of when to use it is if you have a random
code which prevents automated form submission (such as the submission code
at http://addurl.altavista.com/addurl/new). Obviously, you don't want this
data available to the user through a cookie, but you want it available on
the next page so you can check the correct code was entered. So, you store
it in the Session object.

See http://www.w3schools.com/asp/asp_sessions.asp for further information.

Hope this helps,
Blair
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top