note 96995 added to function.setcookie

From: Date: Fri, 26 Mar 2010 15:38:47 +0000
Subject: note 96995 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-167435@lists.php.net to get a copy of this message
To avoid the browser delay when working with cookies, you can create your cookie during the initialization process of your web site. If someone visits *any* page of your site, you should create that cookie with a default value after checking for the default value. Later, when you're working with the cookie, set it to what you need it to and it will be available on the next page the user visits. This helps avoid forcing a browser reload on the client-side. A more refined method of working with cookies is to use my example above and then interact with the cookies using javascript. To review: Perform a conditional check to ensure the cookie does not exist and create it with a controlled default value. (You can later check for the default value when adding meaningful data) <? $cookie_name = "mytestcookie"; if( !isset($_COOKIE[$cookie_name]) && empty($_COOKIE[$cookie_name]) ) setcookie("$cookie_name", 0, 0, "/"); ?> The cookie "mytestcookie" is now accessibly readable and writeable. ---- Server IP: 69.147.83.197 Probable Submitter: 71.41.57.2 ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/96995 Del: integrated -- https://master.php.net/note/delete/96995/integrated Del: useless -- https://master.php.net/note/delete/96995/useless Del: bad code -- https://master.php.net/note/delete/96995/bad+code Del: spam -- https://master.php.net/note/delete/96995/spam Del: non-english -- https://master.php.net/note/delete/96995/non-english Del: in docs -- https://master.php.net/note/delete/96995/in+docs Del: other reasons-- https://master.php.net/note/delete/96995 Reject -- https://master.php.net/note/reject/96995 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167435) next »