note 22492 deleted from function.setcookie by sniper
| From: | sniper@php.net | Date: | Wed, 11 Dec 2002 07:16:34 +0000 |
| Subject: | note 22492 deleted from function.setcookie by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-40726@lists.php.net to get a copy of this message | ||
Three cookie issues:
1. The most common error in setting cookies seems to be that the time difference between the server
and client is not taken into account. If you can wait until AFTER the first page, you could have a
hidden field, formDate, with default value -1 and set it like so upon submission:
function submitClick() {
var today = new Date();
//set the current time;
document.forms.Confirm.formDate.value =
"" + Math.floor(today.getTime()/1000);
}
If the result is negative, you know javascript is not active. Otherwise, just add the number of
seconds into the future that you wish the cookie to expire.
2. To determine right off the bat whether cookies are accepted, when the user first hits the page,
I redirect hir to the same page only setting a cookie AND noting the redirect (I do the latter via
an IP entry in mySQL to avoid infinite loops - your milage may vary). If the cookie is there upon
the immediate return to the page, I know cookies are accepted. Be careful.
3. If you set a cookie, it becomes available to all the windows of the requesting browser. There
is a NOTABLE EXCEPTION: If you set a temporary cookie (one without expiration) then independently
started (by double clicking on the IE icon) threads of IE (at least 5.5 on Windows) will not see the
cookie!