|
|
ASP Cookies
A cookie is object used to identify the user by his/her computer.
Each time the same computer access the page,
the cookie will also be retrieved if the expiry date has future value.
Creating cookies in asp is very simple. Use Response.Cookie
to create a cookie or Request.Cookie to read a cookie.
The following example creates a cookie named userName and assigns value:
<%
Response.Cookies("userName")="user123"
%>
The example bellow will retrieve the cookie we create above:
<%
user=Request.Cookies("userName")
response.write("Welcome " & user)
%>
The result of the above example will look like this:
welcome user123
The cookie will be deleted after your browser is closed unless you set the
expiry date to a future date.
The following example will keep the cookie in place for 30 days after setup date:
<%
Response.Cookies("userName")="user123"
Response.Expires("userName").Expires = Date + 30
%>
You can also set a cookie with multiple values like the following:
<%
Response.Cookies("user")("userName") = "Bell"
Response.Cookies("user")("firstName") = "Bellion"
Response.Cookies("user")("lastName") = "Briabion"
%>
The above Cookie has Keys. When you want retrieve a cookie with
multiple values, you will have to loop through the values using for loop statement
|