Set various cookie expiration times

Source: Internet
Author: User
Set various cookie expiration times

 
The default cookie expiration time is until the browser is closed, and the cookie expires. You can also specify the cookie expiration time.

Response. Cookies ("user_name"). expires = date + 1 'specify the cookie retention time

Keep cookies for one hour

Response. Cookies ("mycookie"). expires = (now () + 1/24)
Response. Cookies ("mycookie"). expires = dateadd ("H", 1, now ())

Set expiration time after 60 months

Response. Cookies ("cookiename"). expires = dateadd ("M", 60, now ())

Response. Cookies ("user"). expires = second () + 7

The time defined after expires can be replaced by the time function.

For example, date () + 7 means that seven days are added to the current time, while second () + 7 means 7 seconds.
Response. Cookies ("field name"). expires = Time Function + N,
For example, response. Cookies ("name2"). expires = date + 1 indicates that cookies are saved for one day,
For another example, response. Cookies ("name2"). expires = hour + 8 indicates that cookies are stored for 8 hours.
I can't test this method (in 2003 Server, iis6.0), no matter whether or not the second is followed (),
A 500 error occurs during access (or cannot the webpage be displayed? Forgot ).
Zhimeng Juventus: We recommend that you use the dateadd function to accumulate the time here. For example, we need to accumulate an hour,
Use: Response. Cookies ("Your dooglecom"). expires = dateadd ("H", 1, now () 30 minutes:
Response. Cookies ("cookiename"). expires = dateadd ("N", 30, now () dateadd ("S", 30, now ())
The expiration date of the cookie specified by the second expires is obtained. To store cookies on the client disk after the session ends,
Or in many cases, we want to save cookies on the visitor's computer for a longer period of time. This date must be set.
If the setting of this attribute does not exceed the current date,

The cookie will expire after the task ends. The cookie expiration date is "January 1, January 1, 2010 ":

Response. cookies ("cookiename "). expires = # January 01,201 0 # The cookie expiration time is "Cookie creation time + 365 days": response. cookies ("cookiename "). expires = date + 365, but it is best not to write response at will. cookies ("cookiename "). expires = date,
In this way, the call time value between pages will be blank.

Function killip (Cook, cooktime) 'blocks IP addresses. The same IP address cannot be executed multiple times. (cookie name, cookie time) killip ("queip", 30)
Cook = checkstr (Cook)
If not isint (cooktime) then
Response. Write "cooktime is not int"
Exit Function
End if
If request. Cookies (Cook) & "" <> "" And request. Cookies (Cook) & "" = getip () then
ExecScript "alert ('sorry, the same IP address cannot be operated multiple times. '); Location. href = '/';"
Response. End
End if
Response. Cookies (Cook) = getip ()
Response. Cookies (Cook). expires = dateadd ("N", cooktime, now. Dateadd ("S", 30, now () 30 seconds. Date + 1 day.
End Function

Call killip ("queip", 30)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.