How would I test if a cookie is set using php and if it's not set do nothing

前端 未结 5 1520
再見小時候
再見小時候 2021-02-07 04:06

I\'ve tried

 $cookie = $_COOKIE[\'cookie\'];

if the cookie is not set it will give me an error

PHP ERROR
Undefined index: cook         


        
5条回答
  •  被撕碎了的回忆
    2021-02-07 04:34

    You can use array_key_exists for this purpose as follows:

    $cookie = array_key_exists('cookie', $_COOKIE) ? $_COOKIE['cookie'] : null;
    

提交回复
热议问题