⊗ppPmCkSP 325 of 447 menu

The Problem of Setting Cookies in PHP

When writing and reading cookies on the same page, there is a certain catch waiting for us. The fact is that cookies set via setcookie become available in the $_COOKIE array only after the page is reloaded.

Let's test this. Let's set a cookie via setcookie and immediately output it. In this case, on the first visit, $_COOKIE for our cookie will be null, and after refreshing the page - the cookie value:

<?php setcookie('str', 'eee'); var_dump($_COOKIE['str']); // first null, then 'eee' ?>

Test the described cookie behavior.

byenru