Thursday, January 2, 2014

How to Prevent / Avoid Form Resubmitting in Php

How to Prevent / Avoid Form Resubmitting in 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