title: How to get the browser to cache images, with PHP?
body: <p>I'm totally new to how to cache images.</p>
  
  <p>I output all images in a gallery with PHP, and want the images already shown, to be cached by the browser, so the PHP script don't have to output the same image again. All I want is the images to show up faster.</p>
  
  <p>When calling an image I do like this:</p>
  
  <pre><code>&lt;img src="showImage.php?id=601"&gt;
  </code></pre>
  
  <p>and the <code>showImage.php</code>-file does:</p>
  
  <pre><code>$id = (int) $_GET['id'];
  $resultat = mysql_query("
      SELECT filename, id
      FROM Media 
      WHERE id = $id
  ");
  $data = mysql_fetch_assoc($resultat);
  
  ...
  
  //Only if the user are logged in
  if(isset($_SESSION['user'])){
      header("Content-Type: image/jpeg");
  
      //$data['filename'] can be = dsSGKLMsgKkD3325J.jpg
      echo(file_get_contents("images/".$data['filename']."")); 
  }
  </code></pre>