PHP POST Submission Caching in Internet Explorer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DFAlpha
Forum Newbie
Posts: 5
Joined: Sun May 11, 2003 12:28 am

PHP POST Submission Caching in Internet Explorer

Post by DFAlpha »

Hey Everyone,

I've got a problem, its a little difficult to explain. I've developed a system using OOP PHP. When you visit the page, it is called as something like this...

mydomain.com?script.php?action=whatever&form=data

Now, when the form is submitted, it is POSTED to itself, query string and all. Sounds pretty standard right, until this happens.

When you submit the form, you would expect to be able to hit the back button and it would return you to the previous menu with the fields, filled, possibly not, but you would still end up with the initial form on your screen. Well, in Internet Explorer 6 (Netscape it works fine, not sure about anything else), when you hit the back button it is the exact same page you just visited with the data submitted and the "Thank you" message, its really odd and quite annoying. When you hit back again, it takes you to the page BEFORE the form.

I've tried using the following code to prevent IE from caching the pages, but it hasn't stopped the problems.

Code: Select all

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
I presume this has something to do with the way IE handles cached forms, but im not sure how to go around it. If anyone has any ideas, I'd really appreciate the help as I've been working with this problem for a long time now.

Regards,
Shawn
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post by trollll »

This actually looks like IE has not cached the page and Netscape has. By telling it explicitly not to cache, you have made sure that the form will never show up again once the user has submitted it. What you can try instead: explicitly tell it to cache the page for a certain period of time. You could even leave out the header() telling it when and if to cache and have php write in the <meta /> tag to cache for ten minutes (or whatever) only when it displays the form.

Hope that helps! :)
DFAlpha
Forum Newbie
Posts: 5
Joined: Sun May 11, 2003 12:28 am

Post by DFAlpha »

Thanks for the idea, I tried adding code to force the cache, but it still didn't seem to work. Any other ideas you may have up your sleeves?

Regards,
Shawn
DFAlpha
Forum Newbie
Posts: 5
Joined: Sun May 11, 2003 12:28 am

Post by DFAlpha »

Hey Guys,

Just wanted to update you on the problem. With much help and a few suggestions, i have found a workaround.

Instead of posting to the identical page, if I add a null post variable to the query string, it works correctly. I think the problem has to do with the way IE inteprets query strings, and how when you simply refresh a page without a query string, its not a problem. However, when you post to an identical page with an identical query string, IE does not recognize the page is different. Weird eh?

Thanks for your help anyhow, its most appreciated.

Regards,
Shawn
Post Reply