开发者

VBScript cookie expiration

I'm wo开发者_开发百科rking 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">


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜