PHP to prevent remote linking of images

From Robupixipedia
Revision as of 00:46, 19 December 2007 by Thunderrabbit (talk | contribs) (wiped out a block of crap that no one will need)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

<digg />

Description

This PHP code is supposed to prevent remote linking of images. I'm just slapping it down here for now and may make it actually work later.

Caveats

I am just slapping this code down here so you can pick out the bits you like. I've stripped most of the code that's specific to my (work) environment, but haven't tested it since then.

Source

<source lang="php"> <?php //***********************************************// // // this code is freeware // //***********************************************//

$image_file_directory = $DOCUMENT_ROOT . "images/"; // prefix for image names in $image_list $image_list = array('good' => 'goodimage.gif', 'bad' => 'bad.gif');

if(preg_match ($VALID_DOMAIN, $_SERVER['HTTP_REFERER'] )

   $name = $image_file_directory . $image_list['good'];

else

   $name = $image_file_directory . $image_list['bad'];
// Date in the past

header("Expires: Wed, 19 Dec 2007 07:41:51 GMT"); // always modified header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // HTTP/1.1 header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); // HTTP/1.0 header("Pragma: no-cache"); // send the right headers $pathinfo = pathinfo($name); $subtype = $pathinfo['extension']; header("Content-Type: image/$subtype"); header("Content-Length: " . filesize($name));


// open the file in a binary mode $fp = fopen($name, 'rb'); // stream the picture out to the browser fpassthru($fp); fclose($fp);

?> </source>