Entry
Why does my browser say "Data Missing" when I use the back button?
Jul 5th, 2004 07:41
Gabriel, Mike Chamberland, Nathan Wallace, matthew mcglynn
The "Data Missing" error is caused by HTTP expires and no-cache headers.
Perhaps a better solution is to set them so that data is cached for a
short period of time -- longer than "zero" but not permanent either.
Of course, for a dynamic site in which individual customized pages are
served to individual browsers, you can't allow caching or you risk that
surfer B sees surfer A's pages because those pages were cached by a
proxy somewhere.
If your problem is that a script that receives a form shows error
messages and ends with "now click BACK to correct the form," the problem
is that that is just a lame design. The solution is to always move
forward, never back, and then you don't have caching problems such as
you've described. Instead of showing error messages with a request that
the user back up, just show the form again and highlight the fields that
have problems. This provides a superior user experience anyway.
This is true if you are only working with form, however if you are
working with a form that shows results to other sources, such as a
search engine, the user needs to go back to the results page NOT the
search form. To explain this in further detail let's say user Y adds an
entry to his database and runs a search - the page is cached so it does
not show the new entry on the results page until the cache expires. The
workaround that I have used is to simply check where the user is
comming from, then set the header to either "nocache" or "private"
Example:
if(!ereg("yourdomain",$PHP_SELF)){
session_cache_limiter('nocache');
} else {
session_cache_limiter('private');
}
This then allows the browser to either cache the page if the user is
returning from an outside url, otherwise they are comming from within
"yourdomain" and you want the page to refresh and show all new data.
However if someone has a better way around this one - I'd like to see
it!
Here it is! Use:
header("Cache-control: private");