title: Echo/print a jpg-image with php, for safety?
body: <p>Because of safety (check if user are logged in), I call a php-document when showing images. </p>
  
  <pre><code>&lt;html&gt;...
  &lt;img src="showImage.php?id=455" /&gt;
  ...&lt;/html&gt;
  
  
  showImage.php:
  &lt;?php...
  
  if($_SESSION['user']){
      //Get the src to the image
      $_GET[$id] = mysql_real_escape_string($_GET['id']); 
      $result = mysql_query("
          SELECT src
          FROM Media 
          WHERE id = '".$_GET['id']."'
          ");
      $data = mysql_fetch_assoc($resultat);
  
      // Output the image
      header('Content-Type: image/jpeg');
      echo(file_get_contents("media/".$data['src']));
  }
  
  ...?&gt;
  </code></pre>
  
  <p>When doing this, I hope the user never will know the direct url to the image, and when trying to show an image, the user has to be logged in. </p>
  
  <p>I'm not sure this is the best way. Is there a more simpler/better way of doing this, and is this safe. When the script is echoing, it's a bit slow.</p>
  
  <ul>
  <li>I want the image to be safe (only logged in user should have access to the image)</li>
  <li>I want the image to be shown as fast as possible</li>
  </ul>
  
  <p>Looking forward for all your expert-tips.</p>