thegunner
thegunner

Reputation: 7153

php reload page without posting data

I'm trying to refresh a page without sending POST from the previous time.

I've tried

window.open("postme.php?r=t", "_self");

Which appends a ?r=t to the end but it doesn't appear to refresh the page as the page displays a number of files in a directory which hasn't change even though I have moved or deleted them.

Can you specify the URL in window.location.reload();?

Any ideas?

Thanks

Upvotes: 8

Views: 12638

Answers (6)

Guest
Guest

Reputation: 31

Redirect the user to the same page after you're finished using their POST data.

$URI = $_SERVER['REQUEST_URI'];

if(!empty($_POST)){
    //magic

    header("location:$URI");
}

Now when you refresh, it won't have POST data to resubmit.

Upvotes: 3

Laurie Clark
Laurie Clark

Reputation: 630

Well.. late too I suppose, but then it could help someone. I used :

window.location.href = window.location.href;

In replacement of location.reload(); this will refresh the page without prompting user to resend information.

Upvotes: 2

user726045
user726045

Reputation: 11

i know this is way late, and hope it applies: i had the same problem where when someone is confirming their inventory selection, it then emails the order [or subtracts from inventory database] then displays their order. then if they refresh, it resubmits the data. so i added a session_destroy(). but then when they refresh, there're lots of errors.

SO - i divided the code into [a]email the order/subtract from the inventory database, then [b]used a javascript "document.location.href='nextPage.php'" because i sometimes have problems using PHP's "location(nextpage.php)". anyway, it emails the info, then goes to the page that displays it. then one can refresh all they want and all that happens is it displays over and over.

hope that helps!

Upvotes: 1

Quentin
Quentin

Reputation: 943214

If you want to avoid having refresh reporting data (for any reason, including the user clicking the reload button) then use the POST-REDIRECT-GET pattern.

Upvotes: 6

thegunner
thegunner

Reputation: 7153

Got this to work...

window.location = "postme.php?r=t";

Upvotes: -1

karim79
karim79

Reputation: 342635

You could try:

window.location.reload(true); //true sets request type to GET

Upvotes: 0

Related Questions