Doug Molineux
Doug Molineux

Reputation: 12431

Refreshing page after posted vars

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?

Upvotes: 0

Views: 95

Answers (2)

Daniel Vassallo
Daniel Vassallo

Reputation: 344291

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.

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157839

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; 
  } 
} 

Upvotes: 4

Related Questions