How to prevent a form from being submitted again?
How to prevent a form from being submitted again?
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Aviance School is one of the largest web solutions platform in India for developers to learn and share their programming knowledge and build their careers.
You can prevent form re-submission using a session variable.
Code:
<form action="" method="post">
<?php
$randnumber=rand();
$_SESSION['RANDNUMBER']=$randnumber;
?>
<input type="hidden" value="<?php echo $randnumber; ?>" name="checkNumber" />
<!-- The Rest of Fields will be goes here -->
<input type="submit" name="submit" value="submit" />
</form>
After check session variable $_SESSION[‘RANDNUMBER’] with textbox $_POST[‘checkNumber’] value Like
<?php
if(isset($_POST['submit']) && $_POST['checkNumber']==$_SESSION['RANDNUMBER'])
{
//Your Code will be goes here
}
?>