Cookie is a text string handle sent to the client's browser and saved on the client's hard disk. It can be used to persistently maintain data between sessions of a web site. Both request and response objects have a set of cookies. The request. Cookie set is a series of cookies that are sent from the client and HTTP request to the web server. If you want to send the cookie to the client, you can use response. Cookie
1. expiresabsolute attributes
This attribute can be assigned a date. After this date cookie is passed, it will no longer be used. You can delete a cookie by assigning an expiration date to the expires attribute. For example:
<% Response. Cookies ("passtime"). expiresabsolute = "1/1/99" %>
2. domain attributes
This attribute defines the unique domain that the cookie will send. For example, if a cookie is sent to only Microsoft users, you can use the followingCode.
<% Response. Cookies ("Domain"). Domain = "www.microsoft.com" %>
3. the syntax used by ASP to write a cookie is as follows:
Response. Cookie ("Cookie name"). [("key name"). Attribute] = content
If an ASP file creates a cookie, the following code can be placed before the first <HTML> of the ASP file to avoid errors.
<% Response. Cookies ("cookiename") = "newcookie" %>
<HTML>
......
</Html>
4. asp uses the cookie set of the request object to read the cookie, for example:
<% Response. Write Request. Cookies ("cookiename") %>
The following uses a complete example to describe COOKIE:
<%
Dim num
Num = request. Cookies ("visit_num ")
If num> 0 then
Num = num + 1
Response. Write "you have accessed this site for" & num. "
Else
Response. Write "welcome to visit this site for the first time. "
Num = 1
End if
Response. Cookies ("visit_num") = num
%>
In this example, read the cookie variable visit_num to check whether the user-side computer stores the cookie variable. If this variable exists, the user has accessed the page and entered the number of visits. If the user visits this page for the first time, there will be no cookies in the computer,ProgramThe "welcome" text is displayed, and the cookie variable visit_num is saved to the user's computer so that the user can provide the "number of visits" information for the next visit to the page.
5. Cookie dictionary
Sometimes many COOKIE variables may need to be defined on a page. In order to better manage them, the one-person sub-key concept is often introduced in cookies ". The syntax for referencing it is as follows:
Request. Cookies ("Change name") ("subkey name ")
The following cookie creates a dictionary named "Dictionary" and stores three key values:
<%
Response. Cookie ("info") ("myname") = "Jeff"
Response. Cookie ("info") ("gender") = "male"
Response. Cookie ("info") ("myheight") = "172"
%>
In fact, the cookie dictionary on the client exists as a string:
Info = myname = Jeff & Gender = male & myheight = 172.
If you directly reference the cookie variable without specifying a subkey name, a string containing all the subkeys and values is returned. For example, the preceding example contains three "subkeys": "myname", "gender", and "myheight". When a user does not specify a "subkey", the request is directly sent. when cookies ("info") are referenced, the following strings are obtained:
Info = myname = Jeff & Gender = male & myheight = 172.
To read all the data in the cookie, use the following code:
<% For each cookie in request. Cookies
If not Cookie. haskeys then
Response. Write cookie & "=" & request. Cookies (cookies)
Else
For each key in request. Cookies (cookies)
Response. Write cookie & "(" & Key & ")" & "=" & request. Cookie (key)
Next
End if
Next
%>