S
Shannon Jacobs
I'm doing some trivial surveys, and I want to know if the same user
answers twice. Can't really know that, but at least I thought I could
check for the same browser/computer combination by using a cookie.
Here is the code I have now. In the header, I have the following:
<SCRIPT language="JavaScript">
var cookieStatus;
if (document.cookie.length > 0) {
cookieStatus = 'Cookie exists with value ' + document.cookie;
} else {
var deadline = new Date();
deadline.setYear(2003);
deadline.setMonth(7);
deadline.setDate(30);
var cookieValue = Math.random(10000);
document.cookie = "cookieValue=" + cookieValue + "; path=/ ;
expires=" + deadline.toGMTString();
cookieStatus = 'Creating new cookie with value' + cookieValue;
}
</SCRIPT>
What is SUPPOSED to happen is that it should check if the cookie
exists, and if so, just return the value in cookieStatus. If there is
no cookie, it is supposed to create one with a random number and an
expiration date of July 30, 2003.
What is happening now is that it seems to think that the cookie has
been created, and it insists it exists. However, there is no cookie to
be found on disk, and usually the value of the cookie is not what I
thought I set it to be... I feel like I'm missing something very
obvious here....
(On the other side, I have this code near the end of the form:
<script language="JavaScript">
document.writeln ('<INPUT type="hidden" name="cookieValue" value="'+
cookieStatus +'">');
</script>
Near as I can tell, this does its job correctly. The problem seems to
be with getting the correct cookie out to the disk.)
I've read various cookie introductions and explanations, and searched
in various places (like this newsgroup), and the behavior is still
mystifying me. The whole thing is a side-effect of something else?
answers twice. Can't really know that, but at least I thought I could
check for the same browser/computer combination by using a cookie.
Here is the code I have now. In the header, I have the following:
<SCRIPT language="JavaScript">
var cookieStatus;
if (document.cookie.length > 0) {
cookieStatus = 'Cookie exists with value ' + document.cookie;
} else {
var deadline = new Date();
deadline.setYear(2003);
deadline.setMonth(7);
deadline.setDate(30);
var cookieValue = Math.random(10000);
document.cookie = "cookieValue=" + cookieValue + "; path=/ ;
expires=" + deadline.toGMTString();
cookieStatus = 'Creating new cookie with value' + cookieValue;
}
</SCRIPT>
What is SUPPOSED to happen is that it should check if the cookie
exists, and if so, just return the value in cookieStatus. If there is
no cookie, it is supposed to create one with a random number and an
expiration date of July 30, 2003.
What is happening now is that it seems to think that the cookie has
been created, and it insists it exists. However, there is no cookie to
be found on disk, and usually the value of the cookie is not what I
thought I set it to be... I feel like I'm missing something very
obvious here....
(On the other side, I have this code near the end of the form:
<script language="JavaScript">
document.writeln ('<INPUT type="hidden" name="cookieValue" value="'+
cookieStatus +'">');
</script>
Near as I can tell, this does its job correctly. The problem seems to
be with getting the correct cookie out to the disk.)
I've read various cookie introductions and explanations, and searched
in various places (like this newsgroup), and the behavior is still
mystifying me. The whole thing is a side-effect of something else?