note 124276 added to function.setcookie

From: Date: Wed, 09 Oct 2019 09:28:32 +0000
Subject: note 124276 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-212560@lists.php.net to get a copy of this message
Be warned! PHP will mangle the names of incoming cookies far more than others have detailed below! Theoretically, the following non-alphanumeric characters are allowed in a cookie name: !#$%&'()*+-./:<>?@[]^_`{|}~ However, if you do this: <?php setcookie('!#$%&\'()*+-./:<>?@[]^_`{|}~', 123); setcookie('!#$%&\'()*+-./:<>?@[^_`{|}~', 466); setcookie('!#$%&\'()*+-./:<>?@]^_`{|}~', 789); setcookie('!#$%&\'()*+-./:<>?@^_`{|}~', 'abc'); ?> then this: <?php print_r($_COOKIE); ?> you get this back: <?php Array ( [!#$%&'()*_-_/:<>?@] => Array ( [0] => 123 ) [!#$%&'()*_-_/:<>?@_^_`{|}~] => 456 [!#$%&'()*_-_/:<>?@]^_`{|}~] => 789 [!#$%&'()*_-_/:<>?@^_`{|}~] => abc ) ?> The rules would appear to be as follows: - Convert all periods to underscores (as detailed below). - Convert all plus signs to underscores. - Convert all unmatched open square brackets to underscores. - Square bracket pairs mean the value is an array; ignore everything after the closing square bracket. Note that these rules are only applied by PHP when generating the $_COOKIE array; the cookie name part in the headers sent by your browser and as received by PHP are exactly as you specified above; <?php echo $_SERVER['HTTP_COOKIE']; ?> gives <?php !#$%&'()*+-./:<>?@[]^_{|}~=123; !#$%&'()*+-./:<>?@[^_{|}~=456; !#$%&'()*+-./:<>?@]^_{|}~=789; !#$%&'()*+-./:<>?@^_{|}~=abc ?> It would be nice if the official notes mentioned this conversion. ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.195 (proxied: 213.105.83.130) ---- Manual Page -- http://php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/124276 Del: integrated -- https://master.php.net/note/delete/124276/integrated Del: useless -- https://master.php.net/note/delete/124276/useless Del: bad code -- https://master.php.net/note/delete/124276/bad+code Del: spam -- https://master.php.net/note/delete/124276/spam Del: non-english -- https://master.php.net/note/delete/124276/non-english Del: in docs -- https://master.php.net/note/delete/124276/in+docs Del: other reasons-- https://master.php.net/note/delete/124276 Reject -- https://master.php.net/note/reject/124276 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#212560) next »