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?

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.

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.

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.