Forum Moderators: coopster

Message Too Old, No Replies

Need simple line of code to block visitor based on referrer

         

brinked

3:45 am on Apr 30, 2010 (gmt 0)

10+ Year Member



So someone is scraping one of my sites daily.

The referrer is always similar...its an internal IP address but the scraper script always has the same name like scraper-script.xml

I would like a simple line of php code that pretty much says

if referrer string contains the word "scraper" then deny access to website. I know strstr is a function that can read a string within a word or something...can someone help me put something together if its not too much of a hassle?

Or any other recommendations? I tried blocking the IP but the IP for the visitor keeps changing.

TheMadScientist

5:32 am on Apr 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Mod_Rewrite...

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} scraper
RewriteRule .? - [F]

b0r1s

3:23 pm on Apr 30, 2010 (gmt 0)



$ref=$_SERVER['HTTP_REFERER'];
if (preg_match('/scrapper/',$ref)){ exit; }

Not tested but should work !

brinked

5:03 am on May 1, 2010 (gmt 0)

10+ Year Member



thanks guys works great!

dreamcatcher

8:44 am on May 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$ref=$_SERVER['HTTP_REFERER'];
if (preg_match('/scrapper/',$ref)){ exit; }


Referer isn`t always set, so should be:

if (isset($_SERVER['HTTP_REFERER'])) {
$ref=$_SERVER['HTTP_REFERER'];
if (preg_match('/scrapper/',$ref)){ exit; }
}

dc