1

I have created a cookie with a filmvalue. now i need to check if the cookies value is equal to the same filmvalue or to another value.

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

If the filmvalue is equal to the filmvalue already voted on then do the above code. but if the film is not voted on then do some other code.

is there a way to do something like this:

if(isset($_COOKIE[votecookie] && $cookiefilmvalue = $film)) 
    { 
    echo "Sorry You have already ranked this film <p>"; 
    header("location: films.php?id=$id");
    exit();
    } 
1
  • fist, try replacing = with == in your if clause Jan 6, 2014 at 19:46

2 Answers 2

12

Erm, yeah...

if(isset($_COOKIE['votecookie']) && $_COOKIE['votecookie'] == $film)

Also, make sure you stick quotes around the elements, it stops PHP throwing a warning like:

Notice: Use of undefined constant votecookie - assumed 'votecookie' in...
1
  • thank you! i fixed the error, it's my first time using cookies so sorry for this noob question.
    – Looptech
    Jan 6, 2014 at 19:59
1

Two problems:

  1. You have misplaced brackets
  2. You are assigning something with =, not checking for equality with ==

Use this

if(isset($_COOKIE[votecookie]) && $_COOKIE[votecookie] == $film)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.