Daniel is absolutely right, the most effective way to prevent reposting is
to process the form variables and then redirect the browser to the
destination page. If the user refreshes, the destination page will be
refreshed and not the script that processes the form.
To do this, you will have to make sure that you have not sent any headers
BEFORE redirecting. Any kind of HTML output such as echo or print will cause
headers to be sent automatically, so you must process the form variables
without using them. Note also that when you use the header redirect all the
local PHP variables will be reset, including any notice or warning/error
message that you have created while processing the input. Therefore, you
must use sessions to save any variables you intend to use on the destination
page. You should also call exit() after redirecting.
To be exact, do something like this:
<?
// this point must be the start of the script (or no headers sent before
this line)
session_start();
if(isset($_POST))
{ // process form variables
// ... insert into table, etc
// ... set session variables you want to keep using
$_SESSION["pagevars"] = ...
header("location: destination_url.php");
exit;
}
// ... code to run if no form was submitted:
?>
ECRIA
http://www.ecria.com