
Untitled
By: a guest on
Jun 26th, 2012 | syntax:
None | size: 0.75 KB | hits: 9 | expires: Never
mod_rewrite image protection
function getImageFromOutside ( $homePath, $file )
{
if ( file_exists ( $homePath . '/' . $file ) )
{
$contents = file_get_contents ( $homePath . '/' . $file );
return $contents;
}
}
$homePath = 'some_path/img';
if ( isset ( $_GET['uid'] ) )
{
$img = $_GET['uid'] . '.jpeg';
header ( 'Content-type: image/jpeg' );
echo getImageFromOutside( $homePath, $img );
} else {
print_r ( $_GET );
echo file_exists ( $homePath . '/' . $file );
}
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.yourdomain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://yourdomain.com/.*$ [NC]
RewriteRule ^/PublicFiles/*$ /page-about-direct-links.html