I assign a cookie to a variable:
$user_cookie = $_COOKIE["user"];
How can I check if the $user_cookie received some value or not?
Should I use if (empty($user_cookie)) or something else?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use isset() like so:
This tells you whether a key named
useris present in$_COOKIE. The value itself could be"",0,NULLetc. Depending on the context, some of these values (e.g.0) could be valid.PS: For the second part, I’d use
===operator to check forfalse,NULL,0,"", or may be(string) $user_cookie !== "".