note 110368 added to reserved.variables.cookies
| From: | phpdev at localhost dot com | Date: | Tue, 16 Oct 2012 08:20:31 +0000 |
| Subject: | note 110368 added to reserved.variables.cookies | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191318@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 69.147.83.199
Probable Submitter: 94.209.223.124
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.cookies.php
Edit -- https://master.php.net/note/edit/110368
Del: integrated -- https://master.php.net/note/delete/110368/integrated
Del: useless -- https://master.php.net/note/delete/110368/useless
Del: bad code -- https://master.php.net/note/delete/110368/bad+code
Del: spam -- https://master.php.net/note/delete/110368/spam
Del: non-english -- https://master.php.net/note/delete/110368/non-english
Del: in docs -- https://master.php.net/note/delete/110368/in+docs
Del: other reasons-- https://master.php.net/note/delete/110368
Reject -- https://master.php.net/note/reject/110368
Search -- https://master.php.net/manage/user-notes.php