Rob's security guide has this code for tokens:
What stops a 'baddie' from simply viewing the HTML code before submitting their 'fake' form and creating a form field based on the contents of the hidden token field?
Thanks
Code:
<?php
session_start();
if( !empty($_POST['post_id'] ) {
if( !user->is_a_moderator )
die;
if( empty($_POST['token']) || $_POST['token'] != $_SESSION['token'] )
die;
// All fine: delete the post.
delete_post( intval($_POST['post_id']) );
// Unset the token, so that it cannot be used again.
unset($_SESSION['token']);
}
$token = md5(uniqid(rand(), true));
$_SESSION['token'] = $token;
?>
<form method="post">
<p>Post ID to delete:</p>
<p><input type="text" name="post_id" /></p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
</form>
What stops a 'baddie' from simply viewing the HTML code before submitting their 'fake' form and creating a form field based on the contents of the hidden token field?
Thanks