Checking if a Cookie is Set

suggest change

Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set.

Example:

// PHP <7.0
if (isset($_COOKIE['user'])) {
    // true, cookie is set
    echo 'User is ' . $_COOKIE['user'];
else {
    // false, cookie is not set
    echo 'User is not logged in';
}

// PHP 7.0+
echo 'User is ' . $_COOKIE['user'] ?? 'User is not logged in';

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents