Reading from Cookie

So there is such a code.

if (isset($_COOKIE['mypages'])) {
    header('Location: (   )');
} else {
    $visit = "active";
    setcookie("mypages", $visit, time() + 7 * 24 * 60 * 60, $mycook);
}

I go into the browser and look at the cookies, everything is registered, everything is fine, there are cookies, there is a parameter, but $_COOKIE['mypages']does not see anything the next time I log in. And they say the cookie was not found.


Answer 1, authority 100%

Documentation at setcookie, it’s best to do $mycook = '/';

<?php
define("cookie_name",'mypages');
if (isset($_COOKIE[cookie_name])) {
    header('Location: (   )');
}
else {
    setcookie(
        cookie_name,            //  
        'active',               // 
        time() + (7*24*60*60),  //  
        '/',                    // 
        $_SERVER['HTTP_HOST']   // 
    );
}

But in this example, the hostname can be omitted, this mode is used when you have a bunch of subdomains