Because of safety (check if user are logged in), I call a php-document when showing images.
<html>...
<img src="showImage.php?id=455" />
...</html>
showImage.php:
<?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']));
}
...?>
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.
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.
- I want the image to be safe (only logged in user should have access to the image)
- I want the image to be shown as fast as possible
Looking forward for all your expert-tips.