VBScript cookie 过期
我正在研究我继承的一些旧代码。在index.asp 文件的顶部有一个VB 脚本,用于在登录时设置COOKIE。查看代码,看起来 cookie 应该在 Date() 过期(我假设是同一天)。然而,当我查看今天创建的 Cookie 时,它将于 10/7/2041 过期。我的目标是让 cookie 在 7 天后过期。提前致谢。
<%@ LANGUAGE=VBScript %>
<% Option Explicit %>
<%
Response.Buffer=true
On Error Resume Next
%>
<%
Dim cookieECP
Dim fldIAccept
cookieECP=Request.Cookies("ACIntra")
fldIAccept=Request.Form("fldIAccept")
if cookieECP="ON" then
Server.Transfer("/default.asp")
elseif fldIAccept="Y" then
Response.Cookies("ACIntra")="ON"
Response.Cookies("ACIntra").Expires = Date()
Server.Transfer("/default.asp")
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
I'm working on a bit of old code that I inherited. There is VB script at the top of the index.asp file which is used to set a COOKIE at login time. Looking at the code it appears as though the cookie should expire on Date() (which I assumed was the same day). However, when I look at the Cookie I created today, it expires on 10/7/2041. My goal is to have the cookie expire in 7 days. Thanks in advance.
<%@ LANGUAGE=VBScript %>
<% Option Explicit %>
<%
Response.Buffer=true
On Error Resume Next
%>
<%
Dim cookieECP
Dim fldIAccept
cookieECP=Request.Cookies("ACIntra")
fldIAccept=Request.Form("fldIAccept")
if cookieECP="ON" then
Server.Transfer("/default.asp")
elseif fldIAccept="Y" then
Response.Cookies("ACIntra")="ON"
Response.Cookies("ACIntra").Expires = Date()
Server.Transfer("/default.asp")
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以使用 dateAdd 进行更多控制。
Response.Cookies("ACIntra").Expires = DateAdd("d",7,date())
采用三个参数 - 您要添加的间隔类型(“d”= 天)、其中的数量
间隔(负减而不是加),以及要添加到的基本日期/时间对象。
您可以使用
date()
或now()
任一;date
获取当前服务器日期,now
还获取当前服务器日期和时间戳。You can also use dateAdd for more control.
Response.Cookies("ACIntra").Expires = DateAdd("d",7,date())
Takes three parameters - the type of inteval you are adding ("d" = days), the number of those
intervals (negative subtracts instead of adds), and the base date/time object you are adding to.
You can use
date()
ornow()
either one;date
gets the current server date,now
gets the current server date and timestamp as well.Date() 是 ASP 中的当前日期。也许您的 cookie 在网站的其他地方已更新?
要在 7 天后过期,说明如下:
我建议您清除浏览器中的所有 cookie,并将浏览器设置为在设置新 cookie 时询问您。 IE 有这个选项,它允许您查看服务器想要在您的浏览器中设置的 cookie/值。
这允许您进行调试。
另一种选择是您的服务器设置了错误的日期,但这有点牵强。
华泰
埃里克
Date() is the current date in ASP. Maybe your cookie is updated somewhere else on the site?
To expire in 7 days, the instruction would be:
I would suggest you clear all cookies in your browser and have your browser set to ask you when a new cookie is set. IE has this option, and it allows you to look at what cookie/value the server wants to set in your browser.
This allows you to debug.
Another option is your server has a wrong date set, but that's a little more far fetched.
HTH
Erik