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 som开发者_StackOverflow中文版e reason it doesn't is there another way to accomplish this?
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;
}
}
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.
精彩评论