Forum Moderators: coopster
// This creates and sets the random number as a session variable
$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;
// In my form I have the line:
echo "<input type=\"hidden\" name=\"token\" value=\"".$token."\" />";
Then when I compare $_POST['token'] and $_SESSION['token'] they don't match.
Am I missing something or is my $token being regenerated every time it's used?
But you just need to make sure you are not running $token = md5(uniqid(rand(), true)); again.
uniqid is based on the current time in microseconds to generate what it generates, but can't see why it should be changing the value of the variable $token.
Is it being run again?
$token = md5(uniqid(rand(), true));
This may help with your issue -
Not that is should make any difference but have you tried
<input type=\"hidden\" name=\"token\" value=\"".$_SESSION['token']."\" />";
This works for me on a page that processes itself, but when I pass the form data to a separate page for processing it doesn't.
Ok, I found the problem...
Just as I was thinking of it, I check to see if there was an included page that was trying to do the same thing and there was. So $token was being set twice.
Always check your includes!