Welcome to WebmasterWorld Guest from 35.171.45.91

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Caching Issue

Caching & Session Issues

     
11:19 pm on Jan 23, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


OK, I have been trying to fix this problem for months - and it is still a huge issue! PLEASE HELP!

EXAMPLE #1:
Person logs into website to place an order - adds a couple products to their cart... then adds another item... but all previous items are gone - just the newest item is there. I've figured out this issue, and all the items are in the database, but for some reason, a new session ID was generated along the way. When that happens, the customer thinks they lost the items in their cart.

I have only been able to recreate this issue with IE, but... 98% of our customers use IE.

EXAMPLE #2:
Customer Logs in as USER1... browses around. Then logs out and logs in as USER2... but the site is still showing as USER1 (at the top of each page it says "Welcome USER1").... BUT, if the person holds their Ctrl+Refresh (to force a Refresh in IE) - it will show them what they should see "Welcome USER2".

Both issues are extremely frustrating and I cannot find the cause. Below is some info I'm hoping someone can look @ and recognize the problem.

[PHP.INI]
-------------------------------------------
session.cache_limiter = private_no_expire

[PHP CODE]
-------------------------------------------
(On every page I have the following bits of code...in the order provided, but with other code left out of course.)

header("Cache-Control: no-store, no-cache, must-revalidate");
header ("Pragma: no-cache");

session_register("REFERRAL_URL");
session_start();
$SID = session_id();
$REFERRAL_URL = $referring_url;
session_register("SID");

10:36 am on Jan 24, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 24, 2006
posts:2
votes: 0


Hi

I once had that problem whereby everytime you go to the next page, it create a new session ID, luckly for me it was an intranet site, so this is how I solved that problem
Every time you log in, it create a file with your IP address eg (145.234.22.9.ini) inside that file I store the session ID that you logged in with. Then always read the file and retrive the session ID." Is not an best way to do it but it worked.

As for many files. I delete a file according to the last access time (if it was more than 4 hours ago) We didn't believe one can be in one page for more than 4 hour.

Sorry I could not help only to share my problem too.

7:23 pm on Jan 24, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


Ya, that won't help too much in this case. My biggest problem I would have to say is the CACHING issue! It drives me nuts. We lose SO MANY customers when they go to log in, and it will say "Welcome User1"... then they click on another page (that they have already visited) and it will say they are not logged in (because IE has cached the page)
11:16 pm on Jan 24, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


One sure way to keep it from caching is to secure it (SSL/https). I realize that is not the answer but it would definitely eliminate caching issues.
12:24 am on Jan 25, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 31, 2005
posts:1108
votes: 0


You might also want to look at setting the Expire header to -1.
e.g. header("expires: -1");
3:32 am on Jan 25, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


I have tried:
header("Expires: -1")
but that didn't help at all

I found a few articles that describe the caching problem with IE .... both articles gave pretty much the same answer saying it definately fixes the issue with IE wanting to cache... I did it, but IE is still caching (and I did clear my cache before opening IE again). Here is what I did

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header('Cache-Control: no-store, no-cache, must-revalidate');
header("Cache-Control: max-age=0");
header("Pragma: no-cache");

Any Clues?

3:42 am on Jan 25, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


I just checked to see what headers IE is receiving... and this is what it is is getting (used ieHTTPheaders v1.6)

HTTP/1.1 200 OK
Date: Wed, 25 Jan 2006 03:37:38 GMT
Server: Apache/2.0.46 (Red Hat)
Accept-Ranges: bytes
X-Powered-By: PHP/4.3.2
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu, 18 Aug 2005 18:51:00 GMT
Cache-Control: private, max-age=10800, pre-check=10800
Pragma: no-cache
Set-Cookie: PHPSESSID=01caf9cda2949486a2ed3c16f9380caf; path=/
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

The one that has me concerned is:
Cache-Control: private, max-age=10800, pre-check=10800

Why is IE receiving that if I'm defining the "Cache-Control" in my own headers @ the very top of the script?

2:46 am on Jan 26, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 31, 2005
posts:1108
votes: 0


I have no idea why it is doing that.

Sometimes the only way to stop IE caching certain things is to make it think that it is a new URL.
I struck this with external JavaScript files.
You would make a change to the JavaScript, but IE would use an old cached version of it until you cleared the cache. In the end I made sure that all the paths to the external JavaScript had a paremeter after it as follows
?ver=###, where the ### got dynamically written from a value in a configuration file, so each time a new version was deployed, it would force IE to reload the JavaScript.

5:08 am on Jan 26, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Aug 29, 2003
posts:236
votes: 0


Well, this may fix my issue if anyone can answer "why", when I'm statying

header("Cache-Control: no-cache");

the browser is receiving

Cache-Control: private, max-age=10800, pre-check=10800

2:12 pm on Jan 26, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


I am inclined to think that it is the order of the session_start() and header() output but don't have time to test the theory myself. Try pushing content back to the browser at each step along the way to nail down when the headers are changing. To do so, you could just exit the script at that point with a generic text string value.