i have a site that works much like classifieds ads. users can post ads and images.
i would like to set the site up so that visitors can only view images on the site in my php pages. in other words, i want to prevent any user from accessing an image directly by its URL.
I'm guessing that half of this problem is putting the images OUTSIDE of the public_html folder. the other half would be to create a php file that only feeds up the files to authorized viewers.
so maybe two files:
==classifed.php==
<?
echo $ad_description . "<br>";
echo "<img src=\"image_feeder.php?image_id=" . $image_id . "\">";
?>
==/classifed.php==
==image_feeder.php==
<?
// determine if request is valid here?
// deny access to direct access that don't come from my php page
define('IMAGE_PATH', '/home/foo/bar/images/');
$sql = "SELECT image_filename FROM images WHERE id=" . $_GET['image_id'];
$result = mysql_query($sql)
or readfile('images/not_found.gif');
$row = mysql_fetch_assoc($result)
or readfile('images/not_found.gif');
readfile(IMAGE_PATH . $row['image_filename']);
?>
==/image_feeder.php==
NOTE: I do NOT want to force users to login to see images. I just want to force them to view the images in my page.