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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 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");

}

?>

...

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.