I have a security token that is created when a page loads and writes that token to a file. Then I confirm that the token passed in the form matches one of the tokens in the file.
This first section is located in the FORM.PHP file, and I can confirm that the token is being written to the file.
//Create Token
$token = md5(time());
//Save token to file
$fp = fopen('/PATH/tokens.txt', 'a') or die ("Unable to open to Token file");
fwrite($fp, "$token\n") or die ("Unable to write to Token file");
fclose($fp);
This section of code is located in the PROCESS.PHP file. I have printed out the contents of the $tokens array and I can manually confirm that the same token is in there.
$tokens = file('/PATH/tokens.txt') or die("Unable to read file");
$token = $_POST['token'];
if (in_array($token, $tokens)){
error_log("Found Token");
} else {
error_log("Token Not Found");
}
I can't figure out why the in_array($token, $tokens) function is not returning TRUE.