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

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

    Use isset to see if the cookie exists.

    if(isset($_COOKIE['cookie'])){
        $cookie = $_COOKIE['cookie'];
    }
    else{
        // Cookie is not set
    }
    

提交回复
热议问题