I have been using the following method for years (allbeit there are opposing philosophies on this subject, however I have never suffered any significant disadvantage):
I always submit a script to itself. Look something like the following:
<?
$errors = array();
if ( isset($_POST['button']) ) {
//check for errors
if ( empty($_POST['randomfield']) )
$errors['randomfield'] = "Please enter something!";
if ( count($errors) == 0 ) {
//process form ...
//...
// redirect to confirm page...
if ( !headers_sent() ) {
/* 99.9999% of the time no headers have been sent and
user is redirected to a success page that they can
reload all day and never get the repost message. */
header("Location: /confirmpage.php");
} else {
// this is just a failsafe.
echo "Everything was submitted just fine.";
}
}
}
?>
<html>
<body>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<input type="text" name="randomfield" value="<?=$_POST['randomfield']?>">
<? echo $errors['randomfield']; ?>
<input type="submit" name="button" value="Go">
</form>
</body>
</html>
Cheers!