PHP: How To Blocking Bad Referrer Site

In this short tutorial we will learn how to blocking bad referrer site using php script. This idea coming into my head after I’m sick looking at bad referrer site which take opportunity to earn money using my articles. Example: the baddest shortest URL adf.ly, this site shorten URL but it’s reported contain spyware and malware on ads from that page.

This will lead our site in problem because people may think we’re spreading spyware/malware. Even if we claim we don’t created that link I believe 99% people wouldn’t trust us. The best thing to stop this madness is blocking that referrer site to stop referring people into our page.

This php script will using php referrer function to detected referrer site. In this short code sample we may will be needed more manual working. I believe someone can created better one or maybe a nice plugins? you’re ALLOWED to use this script code.

Before I’m going to write the code I just want to tell everyone I already try to blocking bad referrer via .htacces file but it’s not working, I believe there something missing on there… So here is the sample code:

[to_plus]

<?php
if ($_SERVER[‘HTTP_REFERER’]){
if ($_SERVER[‘HTTP_REFERER’] == ‘BAD-SITE-URL-HERE’) {
echo “REFERRER FROM BAD-SITE-URL HAS BEEN BLOCKED”;
exit;
}
}
?>

The problem is when we’re trying to block another bad site we have to edit this code manually. I hope someone would try to make plugins using this code. At least this code works when I try to blocking some referrer from adf.ly it’s SUCCESS!

For wordpress user where to put this code? Open your admin panel and edit your header.php file, put this code in the top of your header code. This sample script will checking, if referrer coming from badsite it will stop loading pages and giving warning message. When it coming directly of safe site like google, yahoo, bing, etc it will work as usual.

That’s my share for today, happy weekend everyone, enjoy your day 🙂

Similar Posts:

RELATED SEARCH TERMS:

4 thoughts on “PHP: How To Blocking Bad Referrer Site”

  1. great … I was looking for this … same with me, there are people who generate dollars from adf.ly and the link leads to articles that I created.
    through. htaccess still does not work, now I want to try the above tricks and additional links.

  2. german to English translation

    Unquestionably believe that which you said. Your favorite justification seemed to
    be on the web the easiest thing to be aware of.
    I say to you, I certainly get irked while people think about
    worries that they plainly do not know about. You managed to hit the nail
    upon the top and defined out the whole thing without having
    side effect , people can take a signal. Will probably be
    back to get more. Thanks

  3. make money from home

    My spouse and I stumbled over here coming from a different page and thought
    I might check things out. I like what I see so now i am following
    you. Look forward to exploring your web page
    repeatedly.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.