I have set up this example to show that if an iframe is called within a document, the http_referer for the source script of the iframe will be the parent document, just as if it had been called instead from a link.
My question is basically: If a script embedded in an iframe sees the parent as the http_referer, could it be the same for an embedded image?
Regarding authentication etc - I have actually implemented a script to generate and display the image from binary data contained in the database, and that script references and executes an authentication class before it goes any further.
You don't need to use GD if you have the file accurately stored in the database (ie if you use the columns file_size,file_type,file_name,bin_data). You simply use some code like this in the script (uses ADODB):
<?
$conn = &ADONewConnection($db[0]['type']);
$conn->PConnect(
$db[0]['host'],
$db[0]['user'],
$db[0]['pass'],
$db[0]['name']
);
if (!$_GET['id']) {
die();
}
$sql = 'SELECT ' .
'bin_data,' .
'file_type,' .
'file_name,' .
'file_size' .
' FROM attachments WHERE ' .
'id = "' . $_GET['id'] . '"';
$file = $conn->Execute($sql);
header('Content-type: ' . $file->fields[1]);
header('Content-Length: ' . $file->fields[3]);
header('Content-Disposition: attachment; filename=' . $file->fields[2]);
header("Content-Description: PHP Generated Data");
echo $file->fields[0];
?>