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

前端 未结 5 1517
再見小時候
再見小時候 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:20

    Try this:

     $cookie = isset($_COOKIE['cookie'])?$_COOKIE['cookie']:'';
     //checks if there is a cookie, if not then an empty string
    

提交回复
热议问题