Stop POST when I hit F5 on page

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey, I have a webpage to add some data to a mysql database, I am sending this info using POST, the info is sent to the same webpage where it is submitted, the page is just reloaded really.

Trouble is when I hit F5 it wants to resend the POST data which would create duplicate records which I don't want. Is there a way to reset the POST values so the page can be refreshed by the user as they wish without resending any POST data?
 
Well there's probably a MUCH easier way to do it, but I'd include a hash of the data you intend to upload to MySQL in the post. Then get the PhP to check to see if the hash already exists in your table, if it does do nothing if it doesn't upload the data.
 
Submit to a post page which then redirects to the next page (401). That way the post data doesn't carry on to the redirected page.
 
303 is designed for this purpose, but some pre-HTTP/1.1 agents don't handle it :)
10.3.4 303 See Other

The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. This method exists primarily to allow the output of a POST-activated script to redirect the user agent to a selected resource. The new URI is not a substitute reference for the originally requested resource. The 303 response MUST NOT be cached, but the response to the second (redirected) request might be cacheable.

The different URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).
 
Back
Top Bottom