php version - 4.4.4
mysql version - 4.1.22
Previously I tried to prevent hotlinking of images on a clients site using .htaccess and mod_rewrite. It however didn't work for some reason or other and I decided to do hotlinking protection using php. I'm really new to php. I've seen code like the following [CODE=html]<img src="display.ph p?id=1898" border="0" />[/CODE] and have been trying to do this for the site based on this post <Link removed>. I'm having trouble specifically with getting the php script to return an image when queried as above. I've used the following code (edited because of database connection details).
[CODE=php]
<?
//display.php
$dbh=mysql_conn ect("<CONNECTIO N DETAILS...>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("<DATABASE>",$ dbh);
$query="SELECT filename FROM thumbnails WHERE idn=".$_GET["wli"];
$rawdb=mysql_qu ery($query);
$array=mysql_fe tch_array($rawd b);
if (!empty($array["filename"])){
// Output the header
header("Content-Type: image/jpeg");
// Output the image
echo "photos/gallery_".$arra y['filename'].".jpg";
}else{
echo "photos/imagenotretriev able.jpg";
}
@mysql_close($d bh);
?>
[/CODE]
With the corresponding code on an html page used to display the image...
[CODE=html]
<a href="www.somes ite.com" ><img src="display.ph p?wli=1998" alt="" border="0" /></a>
[/CODE]
It doesn't display an image, just the image title.
mysql version - 4.1.22
Previously I tried to prevent hotlinking of images on a clients site using .htaccess and mod_rewrite. It however didn't work for some reason or other and I decided to do hotlinking protection using php. I'm really new to php. I've seen code like the following [CODE=html]<img src="display.ph p?id=1898" border="0" />[/CODE] and have been trying to do this for the site based on this post <Link removed>. I'm having trouble specifically with getting the php script to return an image when queried as above. I've used the following code (edited because of database connection details).
[CODE=php]
<?
//display.php
$dbh=mysql_conn ect("<CONNECTIO N DETAILS...>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("<DATABASE>",$ dbh);
$query="SELECT filename FROM thumbnails WHERE idn=".$_GET["wli"];
$rawdb=mysql_qu ery($query);
$array=mysql_fe tch_array($rawd b);
if (!empty($array["filename"])){
// Output the header
header("Content-Type: image/jpeg");
// Output the image
echo "photos/gallery_".$arra y['filename'].".jpg";
}else{
echo "photos/imagenotretriev able.jpg";
}
@mysql_close($d bh);
?>
[/CODE]
With the corresponding code on an html page used to display the image...
[CODE=html]
<a href="www.somes ite.com" ><img src="display.ph p?wli=1998" alt="" border="0" /></a>
[/CODE]
It doesn't display an image, just the image title.
Comment