Pages

Friday, May 24, 2013

Prevent form resubmitting using php


Simple method for preventing form resubmission using php.

<?php
if(!isset($_SESSION))
{
session_start();
}
if($_POST)
{
if($_SESSION['token'] == $_POST['token'])
{
echo $_POST['txt'];
echo '</br>Submitting';
// Place form action code here
}
else
{
echo 'Re Submitting';
}
}
$_SESSION['token'] = $token = rand();
?>

<form name="frm" action="" method="post" >
<input type="text" name="txt" />
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input type="submit" />
</form>

No comments:

Post a Comment