Cookie properties:
1. ExpiresAbsolute attribute
This attribute can be assigned a date, after which the cookie can no longer be used. Cookies can be deleted by assigning an expiration date to the Expires attribute. like:
<%Response.cookies(passtime).expiresAbsolute=11111%>
If no attribute change is specified, the cookie will disappear when the browser is closed.
2. Domain attribute
This attribute defines the unique domain to which the cookie is sent. For example: Cookies are only sent to this site, you can use the following code.
<%Response.Cookies(domain).Domain=www.aspxuexi.com%>
The syntax used by ASP to write a cookie, that is, to send a cookie to the client, is as follows:
Response.Cookie(Cookie name).[(key name).Attribute]=content
A cookie is something contained in the http header information, so
If an ASP file is to create a cookie, the following code should be placed before any html document to avoid errors.
<%Response.Cookies(CookieName)=NewCookie %>
<html>
...
</html>
ASP uses the Cookies collection of the Request object to read Cookies, such as:
<%Response.write Request.Cookies(CookieName)%>
Below is a complete example to illustrate Cookie:
<%
dim Num
Num=Request.Cookies(Visit_num)
if Num>0 then
Num=Num+1
Response.write You have visited this site for the &Num&th time.
else
Response.write Welcome to your first visit to this site.
Num=1
end if
Response.Cookies(Visit_num)=Num
%>
In this example, the Cookies variable Visit_num is first read to see whether the Cookies variable is saved on the client computer. If this variable exists, it means that the user has visited the page and enter the number of visits. If the user visits this page for the first time, there will be no Cookies variable in his or her computer. The program will display the welcome word, and then save the Cookies variable Visit_num to the user's computer so that the number of visits will be given the next time the user visits the page. .
Cookie subkey
Sometimes it may be necessary to define many Cookies variables in a page. In order to better manage them, the concept of a person's subkey is often introduced in the Cookies component. The syntax for referencing it is as follows:
Request.Cookies(change name)(subkey name)
For example, the following Cookie creates a dictionary named Dictionary, which 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 computer exists in the form of a string:
info=Myname=jeff&Gender=male&Myheight=172
If the user does not specify a subkey name and directly references the Cookies variable, a string containing all subkey names and values will be returned. For example, the above example contains three subkeys: Myname, Gender, and Myheight. When the user does not specify the subkeys and refers directly through Request.Cookies(info), the following string will be obtained:
info=Myname=jeff&Gender=male&Myheight=172
If you want to read all the data in the cookie, you can use the following code to get it:
<%
For each cookie in Request.Cookies
if Not cookie.HasKeys then
Response.write cookie & = & Request.Cookies(cookie)
Else
for each key in Request.Cookies(cookie)
Response.write cookie&(&key&)&=& Request.Cookies(cookie)(key)
next
end if
next
%>