Expiration time of the cookie

Source: Internet
Author: User
Tags set cookie

Set Cookie Expiration Time

The default cookie expiration time is until you close the browser, the cookie expires, or you can specify the cookie time.

Response.Cookies ("user_name"). Expires=date+1 ' Specify cookie save time

Keep cookies for one hours

Response.Cookies ("MyCookie"). Expires= (now () +1/24) response.cookies ("MyCookie"). Expires = DATEADD ("h", 1, Now ())

Set to expire 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 with a time function

For example: Date () +7 means adding 7 days to today's time, while second () +7 is 7 seconds. Response.Cookies ("field name"). expires= time function +n, for example: Response.Cookies ("name2"). Expires=date+1, which means that Cookies are kept for 1 days, for example: Response.Cookies ("Name2"). Expires=hour+8, which means that the Cookies are kept for 8 hours. I have tested this method (in 2003server,iis6.0), no matter if there is no add () behind the second, there will be a 500 error on access (or the page cannot be displayed?). Forget it). Weaving dream Juve: Here is the time to add the suggestion or use the DATEADD function, for example, we have to accumulate an hour, then use: Response.Cookies ("baidooglecom"). Expires = DATEADD ("h", 1, Now ()) 30 minutes: Response.Cookies ("CookieName"). Expires=dateadd ("n", 30,now ()) DateAdd ("s", 30,now ()) Gets the seconds Expires the expiration date of the specified cookie. In order to store the cookie on the client disk after the session ends, or in many cases, we want to save the cookie on the visitor's computer for a longer period of time. The date must be set. If the setting for this property does not exceed the current date,

The cookie expires at the end of the task. The expiry time of the cookie is "January 1, 2010":

Response.Cookies ("CookieName"). expires= #January, 2010# cookie expires at "Cookie creation time + 365 days": Response.Cookies ("CookieName"). expires=date+365 but it is best not to write Response.Cookies ("CookieName") casually. Expires=date, so that the call value between pages is empty.

Function Killip (cook,cooktime) ' Block IP, the same IP cannot be executed multiple times (cookie name, cookie time) Killip ("Queip", () Cook = Checkstr (Cook) If not Isint (cooktime) Then Response.Write "Cooktime was not int" Exit function End if request. Cookies (Cook) & "<>" and request. Cookies (Cook) & "= GetIP () then ExecScript" alert (' Sorry, the same IP cannot be manipulated multiple times. '); location.href= '/'; "Response. End End If Response.Cookies (Cook) = GetIP () response.cookies (Cook). Expires=dateadd ("n", Cooktime,now ()) ' How many minutes. DATEADD ("S", 30,now ()) 30 seconds. Date+1 1 days. End Function

Call Killip ("Queip", 30)

Expiration time of the cookie

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.