cookie problem

D

Dave Vick

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_email.value);
cookieText += "; pw=" + escape(document.login.user_password.value);
cookieText += "; setDate=" + currDate.toGMTString();
// expires in one year
currDate.setFullYear(currDate.getFullYear() + 1);
cookieText += "; expires=" + currDate.toGMTString();
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.toGMTString();
var expDate = new Date(currDate.setFullYear(currDate.getFullYear() + 1));
expDate = expDate.toGMTString();

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

// set password cookie
cookieText = "pw=" + escape(document.login.user_password.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
 
V

VK

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top