Write cookies using ASP with this tutorial. Cookies are a good way to
keep information handy while interacting with the client. No matter how
you feel about cookies, good bad or indifferent, they are an integral
part of many webs. Why not unlock the mystery and write your own?
No matter how you feel about cookies, good bad or
indifferent, they are an integral part of many webs. Why not unlock the mystery
and write your own? Here's a quick rundown on this.
By adding this code to the top of your page you will drop
a cookie on the client. One way to use this is to determine if a user has been
to your site before. This cookie is set to expire on June 15 2005.
Now if you want the cookie to expire when they leave just
don't give it an expiration like so:
<%
Response.Cookies("paco")=1
%>
Here's how to read the cookie and use it to display a
greeting:
<%
If Request.Cookies("paco") = 1 Then
greet = "Welcome Back To Paco's"
Else
greet = "Welcome To Paco's!"
End If
Response.Write greet
Response.Cookies("paco")=1
Response.Cookies(paco").Expires="June 15, 2005"
%>
Now you will note that I set the cookie AFTER I checked
for it. This is because if we write the cookie before checking, it would always
say Welcome Back.