note 110369 deleted from function.setcookie by googleguy

From: Date: Tue, 16 Oct 2012 11:51:24 +0000
Subject: note 110369 deleted from function.setcookie by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191322@lists.php.net to get a copy of this message
Note Submitter: phpdev at localhost dot com ---- Note: When checking if a cookie exist, the in_array() does not work on the $_COOKIE array, you should isset() to check if the cookie exists. <?php /** * part 1, setting cookie */ $name = 'testCookie'; $value = 'testValue'; $expires = time() + (60 * 60 * 24 * 365); $path = '/'; setcookie($name, $value, $expires, $path); /** * part 2, retrieving cookie */ var_dump($_COOKIE); // output: array(1) { ["testCookie"] => string(9) "testValue" } var_dump(isset($_COOKIE[$name])); // output: bool(true) var_dump(in_array($name, $_COOKIE)); // does not work as aspected !!! // ouput: bool(false) echo $_COOKIE[$name]; // output: testValue ?>

« previous php.notes (#191322) next »