tags:

views:

106

answers:

3

Hi

I've got a confusing difference between my localhost (xampp windows) and my domain (FC7 linux). I have a page with a lot of database driven select lists. On update these values are passed to a page that updates databases and confirms this to the user. (I'm monitoring my db's directly and this is happening correctly)

There's a menu option to return back to the input page. Selecting this on my locahost will correctly return the page with the updated values. Selecting this on my domain will return the page with the original values (e.g. the php script appears not to run). I have to refresh (calls the query) then reload (loads values into fields) to get the new values to display.

My experience to date has been with templates keeping PHP and HTML separate so I've never run into this problem before. I've tried a number of alternatives but with little effect - any thoughts?

A: 

Refresh, and then reload? Is there a page interaction that loads the data into the select boxes?

It sounds like there is a browser caching issue here, or else an unusual order of loading data, but we need more details to see how to replicate it.

DGM
OK what do you need?
+1  A: 

The incorrect response you are getting is most likely coming from a cache.

You can use an HTTP header viewer to find out what caching headers your server is sending out, or you can be certain with the LiveHTTPHeaders addon for Firefox.

What you are looking out for:

  • An Expires: header tells the browser to re-use the same page for further requests before a certain date, without checking from the server. The same is true for a max-age= section within a Cache-Control: header. That is, if you are seeing an Expires header or max-age section, then the browser may return a stale (out-of-date) page without going back to the server.

It's vaguely possible that your server, or a proxy server between your browser and your server, is adding cache validators like these to your pages automatically, whereas your server on your localhost isn't. If so, you could try to remove them. Maybe the server admin has configured mod_expires (you could override that in an .htaccess). If it's caused by a proxy server between your browser and your server, you may not have much choice.

A few other things of interest:

  • You should be using a POST request rather than a GET request if it is important that a certain action changes something on the server. Responses to POST requests are never cached (although, if you do Post-Redirect-Get then the get after it may be, but that's another story).
  • Note that your browser caching may behave differently when you are accessing something at 'localhost' compared to accessing it at any other domain, even if the servers are configured the same and sending the same headers. This is at least the case for Firefox (I've seen it myself). IE also has different security zones, which could plausibly affect caching, making it behave differently on localhost.
  • You may force your server to output a Cache-Control: no-cache header and a Pragma: no-cache header. This could be done in PHP using two calls to the header() function. While browsers and proxies shouldn't be defaulting to behaviour that can return a stale result when no validator is given, this at least makes it explicit that you absolutely don't want something cached.

Note also that if you are accessing the web via a proxy server this can also be affecting things, including which caching headers you receive.

thomasrutter
You can also use, and I recommend, Firebug.
St. John Johnson
A: 

I've been researching this further. It turns out that this caching issue only occurs when the site is accessed via my works internet provider! (It's fine if I access it from home, or via another provider).

**A slight correction to my original post ** I have to (1) reload page (2) reserve the URL