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
Expand|Select|Wrap|Line Numbers
- <img src="display.php?id=1898" border="0" />
Expand|Select|Wrap|Line Numbers
- <?
- //display.php
- $dbh=mysql_connect("<CONNECTION 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_query($query);
- $array=mysql_fetch_array($rawdb);
- if (!empty($array["filename"])){
- // Output the header
- header("Content-Type: image/jpeg");
- // Output the image
- echo "photos/gallery_".$array['filename'].".jpg";
- }else{
- echo "photos/imagenotretrievable.jpg";
- }
- @mysql_close($dbh);
- ?>
Expand|Select|Wrap|Line Numbers
- <a href="www.somesite.com" ><img src="display.php?wli=1998" alt="" border="0" /></a>