Here I am creating a cookie.

setcookie('PHPSESSID', 'id'); 

But in the $ _COOKIE array, it becomes available only after a reboot. But how to get it right away?

  • one
    no way. Only force reload the page. For example, the function header('Location: ?'); - Edward

1 answer 1

After the client is transferred (via the setcookie() function), the cookies will be accessed via the $_COOKIE array the next time the page is loaded. $_REQUEST values ​​are also in $_REQUEST .

If it is so important for you to immediately take data from the $_COOKIE , and not from a variable whose value you set via setcookie() , then write this:

 setcookie('PHPSESSID', $id, ...); $_COOKIE['PHPSESSID'] = $id; 
  • I need directly to the cookie, and not just to the array. - Erepaha
  • Already using the header - Erepaha