title: How are images cached when loaded via php script
body: <p>I have a php script acting as a random image generator. The script queries the database for the user's images, and returns the path to one, at random. Here is the portion of the  code responsible for returning the image, once the path has been chosen.</p>
  
  <pre><code>header('Content-Transfer-Encoding: binary');
  header('Content-Type: image/jpeg');
  header('Content-Length: ' . filesize($path));
  echo file_get_contents($path);
  </code></pre>
  
  <p>I am calling it from the client like so</p>
  
  <pre><code>image.src = "/database/getRandomImage.php";
  </code></pre>
  
  <p>Every time I refresh the page I get a new image at random. However, if I call <code>getRandomImage.php</code> multiple times for side by side images, they will all be the same image. If I add a random property to the call like so</p>
  
  <pre><code>image.src = "/database/getRandomImage.php?path=" + Math.random() * 100;
  </code></pre>
  
  <p>The pictures become random. I take this to mean that the browser is caching them based on the random property I passed. The problem is this property has nothing to do with the actual image. Two different images might get cached as the same image, and the same image might not be retrieved from the cache. Is there any way for <code>getRandomImage.php</code> to inform the browser about the picture it is sending back?</p>