Hi there!
Re question 1: Could you either post some more details or send us an email with the exact htaccess and the error messages received? I will look into it to see if we can solve it.
Re question 2: You should find referrer details in your log files. Test by adding an image and see what hits you get in the logs and just whitelist those.
We are considering adding the option to blacklist instead of whitelist to the next version. Meanwhile you can easily reverse the whitelist to a blacklist in your .htaccess file in WP root folder. Simply remove the ! indicating “not”. This is what you should have now:
# BEGIN imaguard
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?yoursite\.com [NC]
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 [R=301,NC,L]
# END imaguard
Here yoursite is being whitelisted (it’s saying on condition NOT yoursite, then rewrite and enable Imaguard. Just change it to:
# BEGIN imaguard
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://(.+\.)?badsite\.com [NC]
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 [R=301,NC,L]
# END imaguard
And you have reversed it to On condiotion badsite then activate Imaguard.
Just remember that if you update Imaguard (settings or version) it will overwrite your changes, so keep a backup of your htaccessfile.
Hope this helped!
Awesome, thanks.
So all I add to .htaccess for question one is the line:
AddHandler x-mapp-php6 .php
This then causes all images with overlay to have the error:
The Image Cannot Be Displayed, http://XXXX.jpg Because It Contains Errors.
p.s. just having a play with the code above and am struggling to get it working, mainly because this might as well be Greek to me! But if the domain i want the images to have the overlay on is: http://images.google.com, what would the code above be?
D
Are you logged into google when testing? Google has recently started sending empty referers more and more often when someone is logged in to google. Another reason to use a whitelist instead of a blacklist.
You can of course block empty referrers but that may cause problems with search engines crawling your site. As an experiment, try:
# BEGIN imaguard
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{HTTP_REFERER} ^https?://(.+\.)?google\.com [NC]
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 [R=301,NC,L]
# END imaguard
Might as I said cause crawler issues, but worth testing it out to see if you can get it to work.
If you have cPanel installed, you can usually click on “latest visitors” test to open an image via google and check what referrer is set (you don’t need cpanel to do this, but it has an easy link and then you just click refresh after the test to see what referrer was set.
I think the main problem I have is that I want some subdomains to work and others not to.
e.g. I want images.google.com to display the overlay, but mail.google.com not to. At the moment if you add a subdomain, it’ll include the main domain in the .htaccess file e.g. google.com which encompasses all of Google’s subdomains.
D
Hi again,
Something like
http(s)?://(.+\.)?google\.com
would match http://google.com, http://www.google.com, https://google.com and https://www.google.com. If you just want it to match specific subdomains, simply type the entire domain:
http(s)?://images\.google\.com
This would match https://images.google.com and http://images.google.com.
For more referrer domains, simply add more lines:
# BEGIN imaguard
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{HTTP_REFERER} ^http(s)?://images\.google\.com [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://groups\.google\.com [NC]
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 [R=301,NC,L]
# END imaguard
However, as I said Google is cheating more and more by simply sending an empty referrer. To catch those you must use ^-?$:
# BEGIN imaguard
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{HTTP_REFERER} ^http(s)?://images\.google\.com [NC]
RewriteCond %{HTTP_REFERER} ^http(s)?://groups\.google\.com [NC]
RewriteCond %{HTTP_REFERER} ^-?$ [NC]
RewriteRule ^(.*)\.(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 [R=301,NC,L]
# END imaguard
But as I said, this may impact how your site is crawled.
Forgot to comment re php 5.4. Could you confirm that your host has bundles the GD lib with the php 5.4 install? It’s required by Imaguard.
Thanks again for all your help on this.
I don’t know about the GD lib. Host is 1&1 if that helps. They’re pretty darn useless!!
They don’t have any info on the GD lib with php 5.4. What you can do is to create a new php file and just put this in it:
<?php phpinfo (); ?>
Is you save that as f ex yourdomain.com/test.php it will show you a list of installed libraries when you run it. You should have a section called GD and under that an entry called GD Version.
This is what I get:
gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.2
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
Ok, that’s not the issue then.
When you have time you can try to stick the line
error_reporting(E_ALL);
into wp-content/plugins/imaguard/index.php in ir_detectpost function like this:
function ir_detectpost($posts) {
error_reporting(E_ALL);
global $wp;
global $wp_query;
Hopefully it will show a php error when you try to open the image again – not just the general “contains errors” error.
OK, tried that and it brings up dozens of errors across the site but when I try the ?test it still comes up with that same error. I’ve had to turn it off for now as this is the live site we’re playing with.