cookie problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Vick

    cookie problem

    Hey all:

    I've got the following code snippet in a function to set a coockie based
    on whether or not the user selects a checkbox. Using an alert the cookie
    text looks fine but when I go to retrieve the values the only one it can
    find is the value for user. I've a few different things and none of them
    seem to work. I'm getting the same thing in both IE and Firefox. The
    only cookie listed is the 'user' with the proper expiration date.

    The code:

    var currDate = new Date();
    var cookieText = "user=" + escape(document .login.user_ema il.value);
    cookieText += "; pw=" + escape(document .login.user_pas sword.value);
    cookieText += "; setDate=" + currDate.toGMTS tring();
    // expires in one year
    currDate.setFul lYear(currDate. getFullYear() + 1);
    cookieText += "; expires=" + currDate.toGMTS tring();
    document.cookie = cookieText;
    document.login. submit();

    However, setting each name value pair as their own cookie seems to work
    fine. As I do here:

    var currDate = new Date();
    var setDate = currDate.toGMTS tring();
    var expDate = new Date(currDate.s etFullYear(curr Date.getFullYea r() + 1));
    expDate = expDate.toGMTSt ring();

    // set user cookie
    var cookieText = "user=" + escape(document .login.user_ema il.value);
    cookieText += "; expires=" + expDate;
    document.cookie = cookieText;

    // set password cookie
    cookieText = "pw=" + escape(document .login.user_pas sword.value);
    cookieText += "; expires=" + expDate;
    document.cookie = cookieText;

    // set setDate cookie
    cookieText = "setDate=" + setDate;
    cookieText += "; expires=" + expDate;
    document.cookie = cookieText;

    document.login. submit();

    As far as I know the first way should work too, anyone know why it
    isn't? Am I doing something wrond and just not seeing it?

    Thanks for any input.

    Dave
  • VK

    #2
    Re: cookie problem

    document.cookie is not a string (or array, or hash, or anything close to
    that): it's a peer to the system cookie store.
    As this is the only official way to access user's file system within the
    standard sandbox, a lot of security measures have been applied, to limit the
    potential "creativity " of "malicious users" (just love this term :)

    In the particular,
    document.cookie = myCookie (write to the cookie store) accepts only one
    key/value pair at once.

    The same time:
    myCookie = document.cookie (read the cookie store) returns ALL key/value
    pairs for the given domain.


    Comment

    Working...