Created
January 12, 2011 10:39
-
-
Save dervn/775997 to your computer and use it in GitHub Desktop.
表单CSRF处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "<input name='rft' type='hidden' value='".random_form_token()."' />"; | |
if(random_form_token($_POST['rft'])){ | |
// | |
} | |
else{ | |
// | |
} | |
function random_form_token($value=NULL){ | |
if($value == NULL){ | |
$token = hash("sha256","tanzmal".microtime()); | |
$_SESSION['random_form_token'] = $token; | |
return $token; | |
} | |
else{ | |
if($value == $_SESSION['random_form_token']){ | |
unset($_SESSION['random_form_token']); | |
return true; | |
} | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment