Jump to content

Is this a: Possible, b: Easy?


richrock

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/142816-is-this-a-possible-b-easy/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.