Asp operates Cookies (including setting [assignment], reading, deleting [setting expiration time]). This is relatively complete. For more information, please refer to the first two articles of Script House.
example:
Copy the code code as follows:
Response.Cookies("letwego")("visiter")="84ww" 'Assignment
Response.Cookies("letwego").Expires= (now() 7) 'Set expiration time (7 days)
userName=Request.Cookies("letwego")("visiter") 'Get Cookies
Response.Cookies("letwego").Expires= (now()-1) 'Delete Cookies and set expiration time (-1 day)
'dateadd("n",30,now()) gets the minutes
'dateadd("S",30,now()) gets seconds
1. Read
Copy the code code as follows:
Response.Cookies("visiter")="aaa"
a=Request.Cookies("visiter")
Response.Cookies("letwego")("visiter")="aaa"
a=Request.Cookies("letwego")("visiter")
2. Set expiration time
Response.Cookies("visiter").expires=dateadd("H",8,now())' means Cookies are saved for 8 hours
Response.Cookies("user_name").Expires=Date 1 'Specify cookie storage time
Keep COOKIES for one hour
Response.Cookies("MyCookie").Expires= (now() 1/24)
Response.Cookies("MyCookie").Expires = DateAdd("h", 1, Now())
Response.Cookies("CookieName").Expires=DateAdd("m",60,now())
Set to expire after 60 months
Response.Cookies("User").expires=second() 7
The time defined after expires can be replaced by a time function
For example: date() 7 means adding 7 days to today's time, while second() 7 means 7 seconds.
Response.Cookies("field name").expires=time function N, for example:
Response.Cookies("name2").expires=date 1, indicating that Cookies are stored for 1 day. Another example:
Response.Cookies("name2").expires=Hour 8, indicating that Cookies are stored for 8 hours.
I have tested this method but it doesn't work (in 2003server, iis6.0). No matter whether there is () after second or not, a 500 error will appear when accessing (still can't display the web page? Forgot).
It is recommended to use the DateAdd function for time accumulation here. For example, if we want to add up one hour, use:
Response.Cookies("baidooglecom").expires = DateAdd("h", 1, Now())
30 minutes:
Response.Cookies("CookieName").Expires=DateAdd("n",30,now())
dateadd("S",30,now()) gets seconds
Expires specifies the expiration date of the cookie. In order to store the cookie on the client's disk after the session ends, or in many cases we want to keep the cookie on the visitor's computer for a longer period of time. This date must be set.
If this property is not set beyond the current date, the cookie will expire after the task ends.
The cookie expiration date is "January 1, 2010": Response.Cookies("CookieName").Expires=#January 01, 2010#
The expiration time of cookie is "cookie creation time + 365 days": Response.Cookies("CookieName").Expires=Date 365 Recommended
But it is best not to write Response.Cookies("CookieName").Expires=Date casually, so that the value will be empty when called between pages.