I think I have a problem with my php page being cached

When my members login they are taken to welcomeBack.php. This page spawns a lightbox to show a marketing message, if it’s determined that this member needs to see it. Once they read the message, and indicate their response, it’s recorded in the database, the session variable $shownCampaign is set to Yes, and then they are redirected to another page where they are given a chance to see the upgrade features that are available.

What is happening now is that some of my members are clicking their browser back button at this point, when takes them back to welcomeBack.php and the lightbox is spawned again. Then they indicate their response and it’s recorded in the database again. I think welcomeBack.php is being cached or something. When testing out this problem I would:

  1. Login to the test server
  2. Be shown the lightbox with marketing message
  3. Indicate my answer and be redirected to the upgrade features page
  4. Edit welcomeBack.php and remove the code that launches the lightbox
  5. Save welcomeBack.php and upload to the test server
  6. Click the browser’s back button
  7. Be returned to welcomeBack.php and the lightbox spawns, even though I removed to code for it

This is why I think welcomeBack.php is being cached. But I have the following code at the very top of welcomeBack.php, so I’m not sure what is happening:

header(“Cache-Control: no-cache, must-revalidate”); // HTTP/1.1
header(“Expires: Sat, 26 Jul 1997 05:00:00 GMT”); // Date in the past

Does anyone have any suggestions?

Thanks!

It could be the server that’s caching the data, but I think it is probably the browser that’s actually caching the data.

So what is the best way to overcome this?

Programmatically, I don’t think there is one. You can’t force a browser to clear cache or get fresh data on every page load - that’s a user setting.

I’m curious as to why users would hit the back button after the popup, though.

Manually clear the browser cache.

For Firefox, it’s in Preference -> Privacy -> Clear Recent History

My apologies, thought this was on a test server.

You can try this; not sure if it will be 100% reliable:

<?php
header(“Expires: Tue, 01 Jan 2000 00:00:00 GMT”);
header(“Last-Modified: " . gmdate(“D, d M Y H:i:s”) . " GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate, max-age=0”);
header(“Cache-Control: post-check=0, pre-check=0”, false);
header(“Pragma: no-cache”);
?>

I don’t think the above will work in all browsers though; definitely not Safari.

My members are experiencing this in production, and I’m duplicating and testing possible fixes on the test server. So this is a bit more complicated than just clearing my browser cache. Thanks though.

Anyone else have any suggestions?

Wow, this code actually worked in Safari for me, but not Chrome. Why can’t web browsers come to an agreement on some basic standards. Any suggested work arounds?

Hmmm…do you have a recent version of Safari installed? I had a similar problem a while back, and Chrome and Safari gave me issues. I thought Chrome resolved this, but obviously not…

As for a workaround for Chrome, I’m honestly at a loss. I don’t think there’s much you can do about it without some javascript hacking (maybe the JS whizzes here can come up with a solution; I’m not very strong in it ).

Just a heads up while you try to figure out a solution for Chrome:

Do not convert the above PHP headers to it’s html equivalents ( using meta tags ); not all browsers will parse them correctly, if at all – big surprise huh? :smiley:

I’m surprised the header stuff arout77 posted doesn’t work fully. Anyway, another idea: to force caching not to kick in give the page a random new name, probably using a query string would do it. welcomeBack.php?876dfjkhsj, welcomeBack.php?678sdk, welcomeBack.php?768kjhfg etc.