VBScript cookie 过期

发布于 2024-12-08 10:45:28 字数 741 浏览 1 评论 0原文

我正在研究我继承的一些旧代码。在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伏妖词 2024-12-15 10:45:28

您还可以使用 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() or now() either one; date gets the current server date, now gets the current server date and timestamp as well.

橙味迷妹 2024-12-15 10:45:28

Date() 是 ASP 中的当前日期。也许您的 cookie 在网站的其他地方已更新?
要在 7 天后过期,说明如下:

Response.Cookies("ACIntra").Expires = Now() + 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:

Response.Cookies("ACIntra").Expires = Now() + 7

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文