richrock Posted January 28, 2009 Share Posted January 28, 2009 Is it possible to prevent the Browser from re-sending POST data when you click the refresh button? It's just that I've noticed some duplications arising from when I was doing style tests, and re-sending the data. Is it possible, or is there a way to get PHP to check what gets sent? Quote Link to comment https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/ Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 Is it possible to prevent the Browser from re-sending POST data when you click the refresh button? It's just that I've noticed some duplications arising from when I was doing style tests, and re-sending the data. Is it possible, or is there a way to get PHP to check what gets sent? You can check, but the easiest way is after they post the data and it is done with what you want to do a header redirect to a "thankyou" page. This will wipe out the post data and prevent it from being duplicated on refresh. Even if you redirect to the same page, it does not really matter. The redirect is key. Quote Link to comment https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/#findComment-748611 Share on other sites More sharing options...
rhodesa Posted January 28, 2009 Share Posted January 28, 2009 yup...piece of cake...what i do on my pages is: <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ //Post was sent //Do all your form processing here //Now forward the browser back to itself with no POST header('Location: '.$_SERVER['REQUEST_URI']); exit; } ?> <html> <body> Here is my page </body> </html> the one downside is you loose any variables...so you can't put something in say...$error...do the header() call, and then print $error. Quote Link to comment https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/#findComment-748613 Share on other sites More sharing options...
premiso Posted January 28, 2009 Share Posted January 28, 2009 the one downside is you loose any variables...so you can't put something in say...$error...do the header() call, and then print $error. You could put the error in session... Then you get to keep it! Quote Link to comment https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/#findComment-748627 Share on other sites More sharing options...
richrock Posted January 28, 2009 Author Share Posted January 28, 2009 Cool - at least I know it can be done. I'll include it in the next version as a new 'feature' Need some sleep though, so thanks! Quote Link to comment https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/#findComment-748667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.