note 125413 added to function.setcookie

From: Date: Sun, 04 Oct 2020 19:36:25 +0000
Subject: note 125413 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-215531@lists.php.net to get a copy of this message
Chrome versions prior to version 67 reject samesite=none cookies. And starting in Chrome version 84 samesite=none cookies without the secure attribute are also rejected. But that doesn't mean you can't set cookies on an unencrypted connection. The simple way around it is to use browser sniffing to detect samesite=none compatible browsers: $cookie_string = 'set-cookie: name=value'; if (!preg_match('/Chrom[^ \/]+\/([0-9]+)[\.0-9]* /', $_SERVER['HTTP_USER_AGENT'], $matches) || $matches[1]>66 && $matches[1]<84) {// match samesite=none compatible browsers $cookie_string.= '; samesite=none'; } header($cookie_string, false);// set cookie ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.172 (proxied: 2601:1c0:c804:34d0:2ddb:251b:e0f9:13ea) ---- Manual Page -- http://php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/125413 Del: integrated -- https://master.php.net/note/delete/125413/integrated Del: useless -- https://master.php.net/note/delete/125413/useless Del: bad code -- https://master.php.net/note/delete/125413/bad+code Del: spam -- https://master.php.net/note/delete/125413/spam Del: non-english -- https://master.php.net/note/delete/125413/non-english Del: in docs -- https://master.php.net/note/delete/125413/in+docs Del: other reasons-- https://master.php.net/note/delete/125413 Reject -- https://master.php.net/note/reject/125413 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#215531) next »