Susan
Susan

Reputation: 1832

VBScript cookie expiration

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">

Upvotes: 0

Views: 6577

Answers (2)

Bradley Staples
Bradley Staples

Reputation: 367

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.

Upvotes: 2

Erik Oosterwaal
Erik Oosterwaal

Reputation: 4384

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

Upvotes: 2

Related Questions