views:

22

answers:

1

I have a three pieces of code that are giving me trouble.

This one sets the cookie

setcookie("verify", "$value", time()+3600);  

This one is on a different page, it makes sure the cookie has the correct value

if ( $_COOKIE["verify"] != file("name.txt")) { 
header("location: notset.html");
} else { die;  }

And this one deletes the cookie

setcookie("verify", "", time()-3600);

The code to write the cookie doesn't actually write the cookie. And the variable is set, but no matter what the cookie will not set. So when I manually input the value by writing "test" and write test to "name.txt" and go to the page with the IF statement, it will take me to notset.html. Any ideas on why this isn't working?

Oh and the delete cookie code works when I enter the test into both the cookie and name.txt. So the delete code works, but the first two do not.

+6  A: 

Your test fails because $_COOKIE["verify"] is a string but file is returning an array (array of lines in the file). If you want to load a file’s content into a string, use file_get_contents.

Gumbo