-1

I am trying to stop php from keeping my form submission but am having difficulties. Here is what I started with.

<?php
echo "<form action='' method='post'>
<input id='scan' class='scan' name='scan' type='submit' value='Scanning' />
</form>";

if(isset($_POST['scan'])){
echo "Very good!"
}
?>

I have tried the following:

if(isset($_POST['scan'])){
echo "Very good!"
unset ($_POST);
}

if(isset($_POST['scan'])){
echo "Very good!"
unset ($_POST['scan']);
}

if(isset($_POST['scan'])){
echo "Very good!"
exit();
}

if(array_key_exists('scan',$_POST)){
echo "Very good!"
unset ($_POST);

}

I just can't seem to figure it out. I would like the $_POST to be reset when I refresh the page or when I click the back arrow to get to this page. In this example I would like the text "Very good!" to not show upon page refresh.

1 Answers1

0

As John Conde suggested, a POST/REDIRECT/GET pattern would be useful. And the link he shared will give you a good base to work with. You need to deal with the POSTed data without outputting anything, then redirect, then output.

You can oversimplify and just dump the post data to a session variable and deal with it on the redirected page.

if($isset[$_POST['scan'])) {
    $_SESSION['post_data'] = $_POST;  
    header('Location: index.php', true, 303);
}

Or you can do all the heavy lifting on the POSTed page, then redirect to an output page.

if($isset[$_POST['scan'])) {
    // do stuff with $_POST that doesn't output.  
    // Store results server-side with reference
    // like a $_SESSION or an id.
    header("Location: index.php?id=$id", true, 303);
}
Luke
  • 640
  • 3
  • 10