Code

Gordon was right, I really should publish the code for blocking referrers from Google Images.

At the absolute top of the code, add this :

<?php
if (substr($_SERVER[‘HTTP_REFERER’],0,20) == “http://images.google”) {
header(‘Location: http://www.dummies-for-destruction.co.uk/404.htm’);
} else {

}
?>

It really is that simple.

An explanation will be added when I’ve got time!


7 Comments on “Code”

  1. Gordon says:

    Finally!!! I have it in writing!!

    “Gordon was right” – mind if I print this off and show the wife?

  2. David says:

    Geeky I know, but I feel that should really redirect to your 403 page, not your 404, since you are explicitly forbidding referrals from Google Images.

    Here’s the equivalent .htaccess code if anyone wants to go that route:


    # Block referrals from all Google Image searches
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?images\.google [NC]
    RewriteRule .* - [F,L]

    To block a specific page:


    # Block referrals from a certain Google Image search
    RewriteCond %{HTTP_REFERER} ^http://(www\.)?images\.google [NC]
    RewriteCond %{REQUEST_URI} page_to_block.html$ [NC]
    RewriteRule .* - [F,L]

  3. David says:

    Oops, forgot to say you’ll need to put

    RewriteEngine On

    above the code snippet, if it’s not there already.

  4. Adrian says:

    Although most of the people who hit my via google images (and I have about 3000 photos on my site) are chaff, I can’t help thinking that blocking those people from the picture they came to my site to find is a bit against the spirit of the internet.

    Also would it not be better to direct them to a specific page explaining why they are blocked than just a 404 page?

  5. Lyle says:

    I did ask about thoughts on this when I wrote the script.

    As it is though, the image itself isn’t even on the page that’s being referenced – I did a link to that image (as in a “click on the link to see it”) which then got hyper-referenced, for some reason I don’t know. So they weren’t getting the image that was being searched for, and I was losing a shitload of bandwidth. A no-win situation.

    I agree, I could do a page explaining why it’s been blocked, but I also referenced that search to be removed from google three times and they didn’t do it. So *shrug* I dunno.

  6. Adrian says:

    It’s a fair point. I just wouldn’t want to block the genuine people who come via google images. I use it a lot, and I am quite proud of my photo album.

    On the other hand I just had to write to a “WhatBoysWant” site (more or less posting other peoples smut) and ask them to take off a picture from my site as

    a) No one asked permission (It wouldn’t have been granted)
    b) They were hotlinking.

    They wrote back and said hotlinking is perfectly fine and legal but they would remove it as a gesture of goodwill. I didn’t need the fight, but bitchfuckwankers haven’t they ever head of decent netetiquette. It may be legal but it’s damn rude.

    The 16 year old Ozzy girl who I caught hotlinking was far more polite and apologetic.

  7. Lyle says:

    I agree – and if the search result actually showed the image on my site, I wouldn’t object so much. But it didn’t, so it was wasting people’s time as well.

    I barred google from my images directory totally a while back, and that’s worked fine. This one, though, was slightly different, in that all it sourced was the URL in a page, rather than the image itself.

    If it linked to an image directly then that would be OK – but in effect I’ve done Google’s job for them, and removed an irrelevant link that also happened to be sucking my bandwidth like a sinkhole.


Leave a Reply

Your email address will not be published. Required fields are marked *