* * *
Cookies are often used to identify users.
* * *
.
In the following example, we will create a cookie collection named "user". The "user" cookie has keys containing user information:
* * *
## Read All Cookies
Please read the following code:
Assume your server passes all the cookies above to a user.
Now, we need to read all cookies passed to a user. The following example shows you how to do this (note that the code below checks if the cookie has keys using the HasKeys property):
<%
dim x,y
for each x in Request.Cookies
response.write("
")
if Request.Cookies(x).HasKeys then
for each y in Request.Cookies(x)
response.write(x & ":" & y & "=" & Request.Cookies(x)(y))
response.write("
")
next
else
Response.Write(x & "=" & Request.Cookies(x) & "
")
end if
response.write "
"
next
%>
**Output:**
firstname=Alex
user:firstname=John
user:lastname=Smith
user:country=Norway
user:age=25
* * *
## What if the Browser Does Not Support Cookies?
If your application needs to work with browsers that do not support cookies, then you have to use other methods to pass information between pages in your application. There are two methods:
### 1. Add Parameters to the URL
You can add parameters to the URL:
Go to Welcome Page
Then retrieve these values in the "welcome.asp" file, as follows:
<%
fname=Request.querystring("fname")
lname=Request.querystring("lname")
response.write("
Hello " & fname & " " & lname & "!
")
response.write("
Welcome to my Web site!
")
%>
### 2. Use a Form
You can use a form. When the user clicks the Submit button, the form will pass the user input to "welcome.asp":
First Name:
Last Name:
Then retrieve these values in the "welcome.asp" file, as follows:
<%
fname=Request.form("fname")
lname=Request.form("lname")
response.write("
Hello " & fname & " " & lname & "!
")
response.write("
Welcome to my Web site!
")
%>