Jump to content

php "the page cannot be refreshed without resending the information"


allsmiles

Recommended Posts

Hi,

I am new to php

-

I ve a simple home.php page with a html form(POST submitted to home.php itself) to submit a txt file, which is parsed and inserted into the mysql db and the result set is displayed on the same page.

 

-

Now, initially when i submit the page, the page is bahaving as expected.

Once i submit a file and get the response printed back, if i try a refresh I get the "the page cannot be refreshed without resending the information' popup .

And when I click on OK, the form details are RE-submitted.

 

-

 

Please help

Thanks!

this is because when you refresh the page it resends the form information and processes it again. 

 

it is known behavior of PHP, this has nothing to do with javascript

 

For this reason you should never refresh a page, or at least have protection against refreshing a page that processes $_POST content

Ofcourse, thats the standard behaviour .

Since I don't prefer to leave my page behave that way, I am looking for alternate solutions.

 

I was able to work it out using two separate php pages, page1 for the front end which submits to page2, which parses and inserts and redirects to page1, which then queries and prints the result.

 

But I prefer using a single page, and redirect to that page at the end of the processing to itself, so that a reload occurs before a possible refresh.

 

I have tried using the header and redirecting to page1 itself, but somehow its getting into a infinite loop and continuous submission.

 

Could anyone suggest how to implement this/ or any alternate solutions...

 

Thank you

  • 4 weeks later...

you did greatly to send back to same page, but the problem is it ran infinitely... so, to solve this, try passing a variable as a GET after you called header() to 'reload' the same page:

 

[page1]

<?php

if (isset($_GET['action'])

{

    // and if $_GET['action'] == "done", OR you can avoid user manipulating your function by manually typing "/?action=done" at the back of the URL, you can use unique/random string or key (maybe a session id?) generated before you call the header() function to reload, and pass it to the $_GET['action']... and within this IF statement, you verify the key...

 

    // successfully done! do whatever you want after reload!

}

else

{

    // here is where you first perform whatever you want it to do...

 

    header("Location: http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."/?action=done");

}

?>

...

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.