+ Reply to Thread
Results 1 to 2 of 2
Thread: I have a cache problem in PHP?
-
07-15-2009 04:25 PM #1
Junior Member
- Join Date
- Jul 2009
- Posts
- 10
- Downloads
- 0
- Uploads
- 0
I have a cache problem in PHP?
Hello, I've made a little game and I have a little problem with it. Every character is loaded with player.php, so sometimes player A will look like player B, but it shouldn't. I'm 99% sure this is a cache problem. The computer thinks that image player A should look like image player B, so it doesn't create player B, but it should! Well, this is at the top of my code at player.php
header("Content-type: image/jpeg");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
but it will still mess up some times. In the game, you can change from a guy to a girl. walk around as one gender, change your gender, then walk around the same path. Sometimes it will load correctly, haha.
-
07-15-2009 04:26 PM #2
Junior Member
- Join Date
- Jul 2009
- Posts
- 10
- Downloads
- 0
- Uploads
- 0
Your methodology is off.
When you send a header indicating a content type of image / jpeg, you cannot exercise cache control on the image itself.
That is, sending Expires, Pragma or Cache-control headers have no effect on image files. They only have effect on HTML files.
Therefore, you need to be sending those cache control headers to the parent HTML output that contains the image, not the image itself; since the browser considersthe HTML file itself as the object which expires, and all media referenced by the HTML file as objects whose cache duration depends on the cache duration of the page which contains them.
In other words, you need to send expiration headers in the PHP pages that contain the avatars, not with the page that is creating the avatars.
It's also possible that in your code, you are experiencing unintentional variable poisoning; that is, you fail to update all affected variables when constructing the new avatar, but only in certain cases, so "old" values are overriding the "new" values you intended to use.
Without seeing your code, that's only a guess.
----------------
Thank for this answer from PM.
Similar Threads
-
Parham's PHP Tutorial
By Ardenn in forum Website Programming DiscussionReplies: 14Last Post: 02-10-2012, 10:55 AM -
PHP template problem
By RiverWire in forum Website Programming DiscussionReplies: 2Last Post: 08-23-2007, 08:45 PM -
Simple PHP Template Tutorial
By theomnis in forum Website Programming DiscussionReplies: 8Last Post: 03-30-2005, 03:39 PM -
PHP Security: PHPSC Site launched!
By alexandru in forum ComputersReplies: 0Last Post: 02-07-2005, 02:28 PM -
PHP Security <- A MUST READ
By alexandru in forum Website Programming DiscussionReplies: 0Last Post: 01-19-2005, 02:59 PM


LinkBack URL
About LinkBacks
Reply With Quote



Bookmarks