prevent theft of the image links to other sites
for facing the theft of files relating to other sites may use the code below: (.zip)
primarily towards normal view this script uses renaming and copying a folder of images which can be viewed, this folder is emptied periodically, blocking the binding of images from other sites. first, to rename and copy the image into a temporary folder. then displays the image in that folder, renamed. to finally empty folder view to prevent third parties sites use path to. use two folders: storage and view.
note: the storage folder must be hidden and can be used as folder upload in attach see the script, folders and demo image
code:
<?php / prevent theft of the image links to other sites*
for facing the theft of files relating to other sites may use the code below:
primarily towards normal view this script uses renaming and copying a folder of images which can be viewed, this folder is emptied periodically, blocking the binding of images from other sites.
*note: the storage folder must be hidden and can be used as folder upload /
// this is the original image in classic way to view echo "ORIGINAL IMAGE "; echo "<img src = "storage/original_image.jpg" alt ="original"/> ";
// prevent hot link start
// create code @rename + image function create_code($length=8,$use_upper=1,$use_lower=1,$use_number=1,$use_custom=""){
$upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$lower="abcdefghijklmnopqrstuvwxyz";
$number="0123456789";
if($use_upper){
$seed_length+=26;
$seed.=$upper;
} if($use_lower){
$seed_length+=26;
$seed.=$lower;
} if($use_number){
$seed_length+=10;
$seed.=$number;
} if($use_custom){
$seed_length+=strlen($use_custom);
$seed.=$use_custom;
} for($x=1;$x<=$length;$x++){
$code.=$seed{rand(0,$seed_length-1)}; }
return($code);
}
/ echo create_code(); // returns for example a7YmTwG4 echo create_code(16); // returns for example Z77OzzS3DgV3OxxP echo create_code(8,0,0); // returns for example 40714215 echo create_code(10,1,1,1,";,:.-_()"); // returns for example or)ZA10kpX /
// rename the image // path may be ' $path = "".$row['picture'].""; ' by mysql $path = "original_image.jpg";
// attach the code $repath = create_code(16);
// copy image into view folder copy("storage/$path", "view/$repath".''."$path") ; echo "TEMP IMAGE "; echo "<img src = "view/$repath".''."$path" alt ="original"/> ";
// clean view dir after each view at 5 seconds function cleantmp() { $seconds_old = 5; $directory = "view";
if( !$dirhandle = @opendir($directory) ) return;
while( false !== ($filename = readdir($dirhandle)) ) { if( $filename != "." && $filename != ".." ) { $filename = $directory. "/". $filename;
if( @filemtime($filename) < (time()-$seconds_old) ) @unlink($filename); } } }
echo cleantmp();
?>
the sistem delete the view folder and hot linking are not available, anyway you may use this error like 404 to redirect into your site,ads,etc
remember, this is just a personal idea