Prevent form resubmitting in php


Simple method to prevent form resubmitting in 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>

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.