Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Cookie problem! Getting error when passing the expire date.

Reply
Thread Tools

Cookie problem! Getting error when passing the expire date.

 
 
paul
Guest
Posts: n/a
 
      04-27-2006
HI! I keep on getting this error and I have tried different things but I am
not sure how to send the expiring date.

The error that I am getting in Firefox 1.5 is

"Error: expires.toGMTString is not a function"

----------------------------------------------------
I have this in a .js file and in the head section.

function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}


I am calling it like this.

<script type="text/javascript">
Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC", "/");
</script>

What Am I doing wrong?

Paul


 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      04-27-2006

paul wrote:
> The error that I am getting in Firefox 1.5 is
>
> "Error: expires.toGMTString is not a function"
>
> ( (expires) ? ";expires=" + expires.toGMTString() : "") +

[snip]
> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC", "/");
>
> What Am I doing wrong?


The toGMTString() method is method belonging to the Date object. In
your example, you are passing a string "Thu, 2 ...etc". Strings don't
have toGMTString() method.

 
Reply With Quote
 
 
 
 
Stephen Chalmers
Guest
Posts: n/a
 
      04-27-2006

"paul" <(E-Mail Removed)> wrote in message
news:1S84g.1806$(E-Mail Removed).. .
> HI! I keep on getting this error and I have tried different things but I
> am not sure how to send the expiring date.
>
> The error that I am getting in Firefox 1.5 is
>
> "Error: expires.toGMTString is not a function"
>
> I am calling it like this.
>
> <script type="text/javascript">
> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC", "/");
> </script>
>
> What Am I doing wrong?


toGMTString must be called for a Date object not a string literal.
Your parameter should be generated thus:

var now=new Date( new Date().setDate( now.getDate() + 31) ) //31 days

although if the expiry is intended to be after a fixed number of days,
rather
than a specific date, your function would look better accepting an integer
and using it as above to specify the expiry date.

--
S.C.


 
Reply With Quote
 
paul
Guest
Posts: n/a
 
      04-27-2006
web.dev wrote:
> paul wrote:
>> The error that I am getting in Firefox 1.5 is
>>
>> "Error: expires.toGMTString is not a function"
>>
>> ( (expires) ? ";expires=" + expires.toGMTString() : "") +

> [snip]
>> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC",
>> "/");
>>
>> What Am I doing wrong?

>
> The toGMTString() method is method belonging to the Date object. In
> your example, you are passing a string "Thu, 2 ...etc". Strings don't
> have toGMTString() method.


HI! thanks for reponding, hmm, how do I translate the date to numeric? do I
do it like 05, 2 06 2001 20:47:11 ? what about the UTC? do you I use a HEX
value?

Paul


 
Reply With Quote
 
web.dev
Guest
Posts: n/a
 
      04-27-2006

paul wrote:
> The error that I am getting in Firefox 1.5 is
>
> "Error: expires.toGMTString is not a function"
>
> ( (expires) ? ";expires=" + expires.toGMTString() : "") +

[snip]
> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC", "/");
>
> What Am I doing wrong?


The toGMTString() method is method belonging to the Date object. In
your example, you are passing a string "Thu, 2 ...etc". Strings don't
have toGMTString() method.

 
Reply With Quote
 
paul
Guest
Posts: n/a
 
      04-27-2006
Stephen Chalmers wrote:
> "paul" <(E-Mail Removed)> wrote in message
> news:1S84g.1806$(E-Mail Removed).. .
>> HI! I keep on getting this error and I have tried different things but I
>> am not sure how to send the expiring date.
>>
>> The error that I am getting in Firefox 1.5 is
>>
>> "Error: expires.toGMTString is not a function"
>>
>> I am calling it like this.
>>
>> <script type="text/javascript">
>> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC",
>> "/"); </script>
>>
>> What Am I doing wrong?

>
> toGMTString must be called for a Date object not a string literal.
> Your parameter should be generated thus:
>
> var now=new Date( new Date().setDate( now.getDate() + 31) ) //31 days
>
> although if the expiry is intended to be after a fixed number of days,
> rather
> than a specific date, your function would look better accepting an integer
> and using it as above to specify the expiry date.


HI! Thanks, I will have to take a different aproach then:

Paul


 
Reply With Quote
 
paul
Guest
Posts: n/a
 
      04-27-2006
Stephen Chalmers wrote:
> "paul" <(E-Mail Removed)> wrote in message
> news:1S84g.1806$(E-Mail Removed).. .
>> HI! I keep on getting this error and I have tried different things but I
>> am not sure how to send the expiring date.
>>
>> The error that I am getting in Firefox 1.5 is
>>
>> "Error: expires.toGMTString is not a function"
>>
>> I am calling it like this.
>>
>> <script type="text/javascript">
>> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC",
>> "/"); </script>
>>
>> What Am I doing wrong?

>
> toGMTString must be called for a Date object not a string literal.
> Your parameter should be generated thus:
>
> var now=new Date( new Date().setDate( now.getDate() + 31) ) //31 days
>
> although if the expiry is intended to be after a fixed number of days,
> rather
> than a specific date, your function would look better accepting an integer
> and using it as above to specify the expiry date.


HI! I am tring somthing else and I get the expired date but I am now having
trouble adding the path

function Set_Cookie(cookieName,cookieValue,nDays,cookiePath ) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue) +
";expires="+expire.toGMTString(); + "path="+cookiePath";
}

I am using this to call it.

<script type="text/javascript">
Set_Cookie("checkpopupwarning", "1", "7", "/");
</script>

I am getting the following as an error:

"Error: unterminated string literal"

I have tried different things but I am still getting this error or
"cookiePath not defined".

Am I adding this together correctly?


Paul


 
Reply With Quote
 
web.dev
Guest
Posts: n/a
 
      04-28-2006

paul wrote:
[snip]
> ";expires="+expire.toGMTString(); + "path="+cookiePath";


First, remove the semicolon from the call to expire.toGMTString()
Second, you have one too many quotes.

So it should be more like the following:

";expires=" + expire.toGMTString() + "path=" + cookiePath;

 
Reply With Quote
 
paul
Guest
Posts: n/a
 
      04-28-2006
web.dev wrote:
> paul wrote:
> [snip]
>> ";expires="+expire.toGMTString(); + "path="+cookiePath";

>
> First, remove the semicolon from the call to expire.toGMTString()
> Second, you have one too many quotes.
>
> So it should be more like the following:
>
> ";expires=" + expire.toGMTString() + "path=" + cookiePath;


HI! Great it works, one thing that I dont understand though is why the
forward slash does not need quotes, is it not a string value?

Paul


 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      04-28-2006
JRS: In article <(E-Mail Removed)>, dated Thu,
27 Apr 2006 22:35:00 remote, seen in news:comp.lang.javascript, Stephen
Chalmers <(E-Mail Removed)> posted :
>"paul" <(E-Mail Removed)> wrote in message
>news:1S84g.1806$(E-Mail Removed). ..
>> HI! I keep on getting this error and I have tried different things but I
>> am not sure how to send the expiring date.
>>
>> The error that I am getting in Firefox 1.5 is
>>
>> "Error: expires.toGMTString is not a function"
>>
>> I am calling it like this.
>>
>> <script type="text/javascript">
>> Set_Cookie("checkpopupwarning", "1", "Thu, 2 Aug 2001 20:47:11 UTC", "/");
>> </script>
>>
>> What Am I doing wrong?


You are already supplying a string, so toGMTString() is not wanted.


>toGMTString must be called for a Date object not a string literal.
>Your parameter should be generated thus:
>
>var now=new Date( new Date().setDate( now.getDate() + 31) ) //31 days


Does not work.

now = new Date(+new Date()+31*864e5) // go ahead 31*24 hours

with (now=new Date()) setDate(getDate()+31) // go ahead 31 days

with (now=new Date()) setMonth(getMonth()+1) // go ahead 1 month

with (now=new Date()) setHours(31*24,0,0,0) // start of 31st day

Technically, IIRC, the format specified for cookies is not exactly that
usually given by toGMTString, but it seems not to matter.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookies expire immediately, not when set to expire Tongass Park Neighborhood Association, Juneau Alaska ASP General 2 11-24-2009 08:24 PM
Forms authorization cookie always set to expire in 2055? Amil ASP .Net 4 07-22-2005 10:14 PM
Session control with Forms authentication and cookie expire time? =?Utf-8?B?SXZheWxvIEd1YmVyb3Y=?= ASP .Net 1 09-05-2004 04:35 PM
Cookie Expire Big E ASP .Net 4 08-31-2004 08:42 PM
Forms Authentication Cookie Does Not Expire Joey Powell ASP .Net 1 12-03-2003 09:14 AM



Advertisments