password protect images
-
I just developed an easy way to protect images on a simple password protected page in wordpress. (a page which uses the inbuilt wordpress password protected page)And you would like the image to be viewed only by the holder of the password.
3 steps to do it:
1) Put a htaccess file in the folder which you want to protect. The folder which holds your image. Text:
deny from all
2) In wp-content/wp-includes/post-template.php find the function post_password_required –
at the end of the function just before return false add this piece of code:
$ok_ip=$_SERVER[‘REMOTE_ADDR’];
$allow_ip=file_get_contents(WP_CONTENT_DIR.’/uploads/secretfolder/.htaccess’);
$allow_ip.=”\n”.’allow from ‘.$ok_ip;
file_put_contents(WP_CONTENT_DIR.’/uploads/secretfolder/.htaccess’,$allow_ip);
return false;
now access is allowed from the IP which has the password. In case of shared IP this might be a problem for you so:
3) Use javascript/jquery $(window).load and make an ajaxcall to a php program which sets
file_put_contents(WP_CONTENT_DIR.’/uploads/secretfolder/.htaccess’,’deny from all’)
this happens after all pictures are loaded and will do for most situations
in case you have much trafic you might just remove actual IP from allowed ips in a similar manner.It also goes well with a plugin like ft protect children pages (not mine)
Try also my new plugin jaip page style
- The topic ‘password protect images’ is closed to new replies.