I'm totally new to how to cache images.
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.
When calling an image I do like this:
<img src="showImage.php?id=601">
and the showImage.php
-file does:
$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'].""));
}
If you are using php to check if the user is logged in before outputting the message, then you don't want the browser to cache the image.
The entire point of caching is to call the server once and then never call it again. If the browser caches the image, it won't call the server and your script won't run. Instead, the browser will pull your image from cache and display it, even if the user is no longer logged in. This could potentially be a very big security hole.