[thelist] ASP/VBScript

Peter Barrett peterb at corel.com
Tue Sep 19 15:57:18 CDT 2000


This is sort of related, and since I lurk so much and say so little I'm
starting to feel guilty :)...

<tip>
BEWARE: COMMON COOKIE PERIL

When setting a cookie in javascript from a page at www.foo.com/bar/mypage.htm,
the cookie will be set with path= '/bar/',
but when setting it from the same page in vbscript, the path will be '/'
(root). This creates two -different- cookies.

If you have a site that uses vbscript for server-side asp, and javascript for
the client side, you can end up failing to retrieve the cookie you thought you
had set, or grabbing obsolete values. To avoid this, always set the path
explicitly in javascript, so that you are only dealing with one copy of each
cookie.


This function sets cookies with path '/' :

function setCookie (name, value)
{
 var argv = setCookie.arguments;
 var argc = setCookie.arguments.length;
 var expires = (argc > 2) ? argv[2] : null;
 var path = (argc > 3) ? argv[3] : null;
 var domain = (argc > 4) ? argv[4] : null;
 var secure = (argc > 5) ? argv[5] : false;

 document.cookie = name + "=" + escape (value) +
      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
      ((path == null) ? "; path=/" : ("; path=" + path)) +
      ((domain == null) ? "" : ("; domain=" + domain)) +
      ((secure == true) ? "; secure" : "");
}
</tip>

"Bailey, Dan" wrote:

> What if "name-you-saved-cookie-as" is not present on the client's machine,
> though?  Do I run into a runtime error?
>
> -----Original Message-----
> From: Luther, Ron [mailto:RLuth at telxon.com]
> Sent: Tuesday, September 19, 2000 3:06 PM
> To: 'thelist at lists.evolt.org'
> Subject: RE: [thelist] ASP/VBScript
>
> Hi Dan,
>
> How about ...
>
> If Request.Cookies("name-you-saved-cookie-as").HasKeys Then

<cut>





More information about the thelist mailing list