How to clear cookies in ASP?

T

tanya.wang

Hi,

I have a website that would set two cookies when a user logs in
successfully.

<%
response.cookies("login_status")="OK"
response.cookies("login_id")="12345" 'This value is from database.
response.cookies("login_id").domain="mysitexyz.com"
%>

and I have a question in "removing/deleting/cleaning the cookie when
the user logs out.

From my understanding there are two methods -

#1 (I am currently using)
response.cookies("login_status")=""
response.cookies("login_id")=""

#2
response.cookies("login_status").expires=now
response.cookies("login_id").expires=now

My questions is, what's the difference, advantage and disadvantage of
these two methods?

I am asking this because I have noticed that there are some problems
in #1. In my computer (I use IE7) if I login as one user, logout, and
then login as another user, the cookie value will get mixed up.
Somehow the response.cookies("login_status") can display correctly but
response.cookies("login_id") cannot. But if I clean my browser cache,
close my IE and reopen it, both cookies work fine.

Anyone has ideas or suggestions will be highly appreciated.
 
T

tanya.wang

in general, the first simply changes the value of thecookie, the second destroys thecookie.

the problem may be touching upon many subjects. Whether or not the login check is working properly depends upon how you are testing
for login existence.

 Are you looking for an empty value in thecookieor checking for the existence of acookie.

I am not looking for an empty value or the existence of it. My problem
happens when I login->logout->login and the cookie value cannot be
stored correctly. I will explain my question more specifically as
below.

1. I tried to login my website with one account (id=12345), I got the
cookie values as follows (which is correct) -

response.cookies("login_status")="OK"
response.cookies("login_id")=rs("myuserid") 'This value is from
database...
response.cookies("login_id").domain="mysitexyz.com" 'Note that I only
set up domain for cookie login_id

If I Response.Write("login_id="& Request.Cookies("login_id") ), I get
login_id=12345
which is correct.

2. Then I log out. The cookie values were set to ""

response.cookies("login_status")=""
response.cookies("login_id")=""

3. After that, I use another user account (id=67890) to login, but I
found that "ONLY" the cookie login_id cannot get the correct value. If
I want to output them like

Response.Write("login_status="& Request.Cookies("login_status")
Response.Write("login_id="& Request.Cookies("login_id")

I got
login_status=OK
login_id=

which is wrong, I should be able to get "login_id=67890" as my correct
result. The login ID and PW were both correct, so it couldn't be the
DB problem. The only one problem that I can think of is at the time
that I logout, I didnt "clean/remove" my cookie completely.

So anyone knows where the problem is? and how to solve it?
 
E

Evertjan.

Jon Paal [MSMD] wrote on 05 jan 2008 in
microsoft.public.inetserver.asp.general:
your logic seems fine but it must be something else in your code or
when you are testing the cookie.

After logging in, redirect to a new page and put the test in the new
page . See if the problem repeats or is resolved.

Please Jon, quote! This is not email.
 
A

Anthony Jones

Bob Barrows said:
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138


D'oh! nice one Bob I didn't think to check the headers. ;)

Jon, I use OE as well. Yet I'm still irritated that when I'm forced to
click between messages trying to get a handle on what the comments should be
applied to. Although not as irritated as opening one of Evertjan's messages
that it bangs on about netiquette yet again. :p
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top