PHP检查cookie值是否等于另一个变量

Loo*_*ech 1 php cookies

我创建了一个带有电影价值的cookie.现在我需要检查cookie值是否等于相同的filmvalue或其他值.

if(isset($_COOKIE[votecookie])) 
    { 
    echo "Sorry You have already ranked this film <p>"; 
    header("location: films.php?id=$id");
    exit();
    } 
Run Code Online (Sandbox Code Playgroud)

如果影片价值等于已经投票的影片价值,则执行上述代码.但如果电影没有投票,那么就做一些其他的代码.

有没有办法做这样的事情:

if(isset($_COOKIE[votecookie] && $cookiefilmvalue = $film)) 
    { 
    echo "Sorry You have already ranked this film <p>"; 
    header("location: films.php?id=$id");
    exit();
    } 
Run Code Online (Sandbox Code Playgroud)

The*_*Dog 11

呃,是的......

if(isset($_COOKIE['votecookie']) && $_COOKIE['votecookie'] == $film)
Run Code Online (Sandbox Code Playgroud)

另外,请确保在元素周围添加引号,它会停止PHP抛出警告,如:

Notice: Use of undefined constant votecookie - assumed 'votecookie' in...
Run Code Online (Sandbox Code Playgroud)