How to return the value of PHP "setrawcookie"?

IETF recommends using base64 encoding for binary cookie values: http://tools.ietf.org/html/draft-ietf-httpstate-cookie-07

So I use setrawcookie(..), but I don’t know which variable to use to return the cookie, because it $_COOKIE[..]still uses URL decoding that matches setcookie(..). This replaces "+" with "" at the output.

<?php

var_dump($_COOKIE['TEST']);
$binary_string = "";
for($index = 0; $index < 256; $index++){
    $binary_string .= chr($index);
}
$encoded_data = base64_encode($binary_string);
var_dump($encoded_data);
$cookie_set = setrawcookie('TEST', $encoded_data, time() + 3600);
?>
+3
source share
1 answer

setrawcookie setcookie. , cookie (cookie ), $_COOKIE .

, cookie $_SERVER['HTTP_COOKIE']. , key1=value1; key2=value2. - :

foreach(explode('; ',$_SERVER['HTTP_COOKIE']) as $rawcookie)
{
    list($k,$v) = explode('=',$rawcookie, 2);
    $_RAWCOOKIE[$k] = $v;
}

var_dump($_RAWCOOKIE);
+7

Source: https://habr.com/ru/post/1742332/


All Articles