Checking if a $_COOKIE value is empty or not

后端 未结 6 1934
盖世英雄少女心
盖世英雄少女心 2021-01-15 12:27

I assign a cookie to a variable:

$user_cookie = $_COOKIE[\"user\"];

How can I check if the $user_cookie received some value or

6条回答
  •  借酒劲吻你
    2021-01-15 13:17

    isset(), however keep in mind, like empty() it cannot be used on expressions, only variables.

    isset($_COOKIE['user']); // ok
    
    isset($user_cookie = $_COOKIE['user']); // not ok
    
    $user_cookie = $_COOKIE['user'];
    isset($user_cookie); // ok
    

    (isset() is the way to go, when dealing with cookies)

提交回复
热议问题