By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,706 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Browser cache causing problem viewing php generated dynamic data

P: 2
I have a PHP 4.4.7, MySql 5.0 and I.E. 7. My PHP queries the database and renders the info into html forms. Submitting the forms manipulates the data.

Now, the problem is that the browsers are caching the dynamic pages. Once the data is updated, returning to the original viewing page shows the old data until you hit refresh.

I know I can have my users adjust their internet file settings to "Check for newer versions of stored pages" to stop this behavior. I don't want to have to rely on users to make browser setting changes. They are challenged enough as it is.

Is there a way I can force the browsers to refresh at each viewing?

I've already tried placing an outdated meta tag in the headers to make the browser think the pages are too old:
Expand|Select|Wrap|Line Numbers
  1. <meta http-equiv="EXPIRES" CONTENT="TUES, 31 DEC 1996 12:00:00 GMT"> 
That doesn't seem to work.

Apr 23 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 5K+
P: 7,435
Browsers don't pay much attention to that anymore. The best method is setting it in the http headers. I don't know how to do that in PHP.
Apr 23 '08 #2

P: 2
I found it after much gnashing of teeth and many google searches. It was right in I guess I just wasn't searching with the right phrases. And I apologize that this is really a PHP issue and not an HTML question.

To manually force PHP web pages to refresh when visited because of dynamic content, you can use the header function:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  3. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
  4. ?>
There are a number of restrictions about the command's location in your script. You can read more at
Apr 23 '08 #3

Expert Mod 5K+
P: 5,390
you could even use a unique additional querystring for the url that is requested ... so instead of requesting:

Expand|Select|Wrap|Line Numbers
  1. foo.php
just request:

Expand|Select|Wrap|Line Numbers
  1. foo.php?my_key=unique_value
where unique-value could be a timestamp added by javascript for example.

kind regards
Apr 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.