If I understand this correctly, it looks like you are setting a token for each request. I assume that the old page still has the old token. I would check if a token is installed before automatically issuing it.
if (isset($_SESSION['token'])){
} else{
$_SESSION['token'] = md5(rand());
}
. .
, "", .
$_SESSION[$sessionId] = md5(rand());
, , , , , , . , . , .
.
http:
, , , - .
2 , , . , , , , , , , -: -)
CSFR , , , , - , , cookie Alice , , . , Alice bank http://www.mybank.com, ,
<img srg="http://www.mybank.com/transferfunds.php?amount=1000&receiver=Bob" />
- , . , (, ), ( , , ):
- , . cookie ( " " ), . , ( ) cookie, , .
- , - .
"" (HTTP), (1). " " .., , . (2) . ( , ) - , , .
,
$_SESSION['token'] = md5(rand());
, , .
http://www.mysite.com/secure.php?token=giuwnrefviunslfghahgliuwnvwrgbaasd
: .. cookie. , - ,
//note, you'll want to sanitize user input, I'm just being brief
if ($_GET['token'] != $_SESSION['token']){
//User either attempted to enter a link on their own or it a CSRF attack
header('HTTP/1.1 403 Forbidden');
}else{
//do whatever needs to be done
}
, . , , , cookie . , , , . ( , , , , , , , , , , .)
, , .