Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.