views:

44

answers:

2

So a form is submitted on my site, with form action equal to itself.

I want the user to be able to refresh the page without sending the same variables again.

I thought unset($_POST); would accomplish this for some reason it doesn't is there another way to accomplish this?

+1  A: 

You may want to tackle this problem by issuing a server-side redirect to a GET request, when the POST request responds. This will prevent the users from refreshing the page and accidentally resending the POST request.

Daniel Vassallo
thanks for your advice Daniel, so do you mean like have form.php and the form_posted.php?
Pete Herbert Penito
use the header function to perform this redirect.
webbiedave
@Pete: Yes. This a popular method to implement the typical `thank_you` page. It is considered good practice to redirect the user to a `thank_you` page generated from a `GET` request, instead of one returned from a `POST` request.
Daniel Vassallo
+4  A: 

No, unset($_POST) wont' help you. As this array being populated from the browser request.

The common practice (and protocol requirement) is to use HTTP redirect to some (usually same) location. A rough outline of a POST form handler in the same file is like this:

if ($_SERVER['REQUEST_METHOD']=='POST') { 
    //write data
    Header("Location: ".$_SERVER['PHP_SELF']); 
    exit; 
  } 
} 
Col. Shrapnel
o okay I see I can use this, thank you Col. Shrapnel!
Pete Herbert Penito
i can't accept for 7 minutes apparently, but i shall when i can thanks again
Pete Herbert Penito