Jump to content

PHP comment page on refresh asks to send data again - dont want - $_POST


shortysbest

Recommended Posts

I have a comment page that people can add a comment to the page on my website. If you submit a comment and then refresh the page i get this message:

"to display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."

 

If you click resend it posts the same comment again, obviously dont want that. How can i reset the $_POST or whatever so it doesnt do this?

Link to comment
Share on other sites

You could do it by including a hidden field in your form,

<input type="hidden" name="control" value="true" />

Then...

On your page that you want to be able to refresh, include

<?php
//any headers or session_start() statements that you have go here.
if(isset($_POST['control'])){
//The Rest Of Your Current Page Code Goes Here
unset($_POST['control]);
}
else{
//only the part of your code that displays the page info, not the part that processes the form gets repeated in here
}
?>

 

And see how that goes.

Link to comment
Share on other sites

if (!empty($_POST)) {
  //process
  if ($insertSuccess) {
    header('Location: ' . $_SERVER['SCRIPT_NAME']);
    exit(0);
  }
}

 

After the user submits the form you process it, and you redirect them to the same page. If you now refresh the page FF does not asks you.

 

Edit: MrAdam beat me to it.

Link to comment
Share on other sites

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.