note 22492 added to function.setcookie

From: Date: Thu, 20 Jun 2002 06:10:00 +0000
Subject: note 22492 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-32030@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! -- http://www.php.net/manual/en/function.setcookie.php http://master.php.net/manage/user-notes.php?action=edit+22492 http://master.php.net/manage/user-notes.php?action=delete+22492 http://master.php.net/manage/user-notes.php?action=reject+22492

« previous php.notes (#32030) next »