+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    10
    Downloads
    0
    Uploads
    0

    Default 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.

  2. WebmasterServe Adverts:
  3. #2
    Join Date
    Jul 2009
    Posts
    10
    Downloads
    0
    Uploads
    0

    Default

    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.

+ Reply to Thread

Similar Threads

  1. Parham's PHP Tutorial
    By Ardenn in forum Website Programming Discussion
    Replies: 14
    Last Post: 02-10-2012, 10:55 AM
  2. PHP template problem
    By RiverWire in forum Website Programming Discussion
    Replies: 2
    Last Post: 08-23-2007, 08:45 PM
  3. Simple PHP Template Tutorial
    By theomnis in forum Website Programming Discussion
    Replies: 8
    Last Post: 03-30-2005, 03:39 PM
  4. PHP Security: PHPSC Site launched!
    By alexandru in forum Computers
    Replies: 0
    Last Post: 02-07-2005, 02:28 PM
  5. PHP Security <- A MUST READ
    By alexandru in forum Website Programming Discussion
    Replies: 0
    Last Post: 01-19-2005, 02:59 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110