Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Preventing Double submit on refresh/back


arvind_gupta - 6:58 am on May 18, 2010 (gmt 0)


I generally tend to use a random key to stop multiple form submission. For eaxmple:

<?php
session_start();

// Process form
if(isset($_GET['submit']) && $_GET['key'] == $_SESSION['key'])
{
// Process
echo 'processed';
}
else {
echo 'not prcoessed';
}
?>

<?php
$_SESSION['key'] = mt_rand(1, 1000);
?>
<!-- Form -->
<form action="" method="get">
<input type="hidden" name="key" value="<?php echo $_SESSION['key'] ?>" />
<input type="submit" name="submit" value="Submit" />
</form>


Hope this helps!


Thread source:: http://www.webmasterworld.com/php/4131929.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com