关于cookie保存时间?

hotbug2002 2004-04-24 08:58:45
reponse.cookies("名字").expires=时间,这个时间是怎样的呢?时间=现在时间+加上要加上的时间,应该是怎么样的呢?就时如何保存cookie,给个例子吧!
...全文
1126 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hotbug2002 2004-04-25
  • 打赏
  • 举报
回复
我用的是javascript脚本呀!这个函数行吗?
假如我保存cookies七天,给个例子吧!
vjlin 2004-04-24
  • 打赏
  • 举报
回复
Response.Cookies("Passport").Expires = DateAdd("n", iExpires, now)

DateAdd 函数

描述
返回已添加指定时间间隔的日期。
语法
DateAdd(interval, number, date)
DateAdd 函数的语法有以下部分:

部分 描述
interval 必选项。字符串表达式,表示要添加的时间间隔。有关数值,请参阅“设置”部分。
number 必选项。数值表达式,表示要添加的时间间隔的个数。数值表达式可以是正数(得到未来的日期)或负数(得到过去的日期)。
date 必选项。Variant 或要添加 interval 的表示日期的文字。

hotbug2002 2004-04-24
  • 打赏
  • 举报
回复
我想知道Response.Cookies("qdn").Expires=现在时间+一段时间,现在时间+一段时间这个如何写呢?
vjlin 2004-04-24
  • 打赏
  • 举报
回复
Sub SaveCookie(CookieName, CookieValue, iExpires)
Response.Cookies("qdn").Expires = DateAdd("d", iEcpires, Date)
Response.Cookies("qdn").Path = "/"
'Response.Cookies("qdn").Domain = "123.CN"
Response.Cookies("qdn").Secure = True
Response.Cookies("qdn")(CookieName) = CookieValue
End Sub
Call SaveCookie("UserName","vjlin",1)
chinaworker 2004-04-24
  • 打赏
  • 举报
回复

Response.Cookies("name").Expires = "当前日期时间+20分钟"
Cookies
The Cookies collection sets the value of a cookie. If the specified cookie does not exist, it is created. If the cookie exists, it takes the new value and the old value is discarded.

Syntax
Response.Cookies(cookie)[(key)|.attribute] = value

Parameters
cookie
The name of the cookie.
key
An optional parameter. If key is specified, cookie is a dictionary, and key is set to value.
attribute
Specifies information about the cookie itself. The attribute parameter can be one of the following. Name Description
Domain Write-only. If specified, the cookie is sent only to requests to this domain.
Expires Write-only. The date on which the cookie expires. This date must be set in order for the cookie to be stored on the client's disk after the session ends. If this attribute is not set to a date beyond the current date, the cookie will expire when the session ends.
HasKeys Read-only. Specifies whether the cookie contains keys.
Path Write-only. If specified, the cookie is sent only to requests to this path. If this attribute is not set, the application path is used.
Secure Write-only. Specifies whether the cookie is secure.


Value
Specifies the value to assign to key or attribute.
Remarks
If a cookie with a key is created, as in the following script,

<%
Response.Cookies("mycookie")("type1") = "sugar"
Response.Cookies("mycookie")("type2") = "ginger snap"
%>

this header is sent.

Set-Cookie:MYCOOKIE=TYPE1=sugar&TYPE2=ginger+snap

A subsequent assignment to myCookie without specifying a key, would destroy type1 and type2. This is shown in the following example.

<% Response.Cookies("myCookie") = "chocolate chip" %>

In the preceding example, the keys type1 and type2 are destroyed and their values are discarded. The myCookie cookie now has the value chocolate chip.

Conversely, if you call a cookie with a key, it destroys any nonkey values the cookie contained. For example, if after the preceding code you call Response.Cookies with the following

<% Response.Cookies("myCookie")("newType") = "peanut butter" %>

The value chocolate chip is discarded and newType would be set to peanut butter.

To determine whether a cookie has keys, use the following syntax.

<%= Response.Cookies("myCookie").HasKeys %>

If myCookie is a cookie dictionary, the preceding value is TRUE. Otherwise, it is FALSE.

You can use an iterator to set cookie attributes. For example, to set all of the cookies to expire on a particular date, use the following syntax.

<%
For Each cookie in Response.Cookies
Response.Cookie(cookie).Expires = #July 4, 1997#
Next
%>

You can also use an iterator to set the values of all the cookies in a collection, or all the keys in a cookie. However, the iterator, when invoked on a cookie that does not have keys, does not execute. To avoid this, you can first use the .HasKeys syntax to check whether a cookie has any keys. This is demonstrated in the following example.

<%
If Not cookie.HasKeys Then
'Set the value of the cookie
Response.Cookies(cookie) = ""
Else
'Set the value for each key in the cookie collection
For Each key in Response.Cookies(cookie)
Response.Cookies(cookie)(key) = ""
Next key
%>

Examples
The following examples demonstrate how you can set a value for a cookie and assign values to its attributes.

<%
Response.Cookies("Type") = "Chocolate Chip"
Response.Cookies("Type").Expires = "July 31, 1997"
Response.Cookies("Type").Domain = "msn.com"
Response.Cookies("Type").Path = "/www/home/"
Response.Cookies("Type").Secure = FALSE
%>



28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧