Log referrer script - add wildcards to domain blacklist?

Hi. I’ve been using a simple script that logs referrers from my visitors, but unfortunately in the last few weeks its been bombarded by fake urls from mostly Russian origin. The script already has a blacklist option so I added the ‘.ru’ to block all Russian domains but sadly urls ending in “.ru/” still get through. I’m not php savvy and would be tremendously grateful if somebody could show me how to add a wildcard feature to the blacklist so I can add things like “.ru”. Thanks and here’s the script:

[php]<?php $file = “refers.txt”; $blacklist = array( ‘.ru’’);
$referrer = $_SERVER[‘HTTP_REFERER’];
$url = ($referrer) ? parse_url($referrer) : false; $refer_text = “{$referrer}”;
if (isset($url[‘host’]) && !in_array($url[‘host’], $blacklist))
file_put_contents($file, “{$refer_text}\n”, FILE_APPEND);
} ?>[/php]

[php]function my_bp_ban_domains( $result ) {
$banned = array(‘ru’, ‘pl’);
$error = ‘Your email domain has been the source of spam. Please use another email address.’;
$email = $result[‘user_email’];
$domain = array_pop(explode(’@’, $email));
$ext = array_pop(explode(’,’,$domain));
if ( in_array($ext, $banned)) {
$result[‘errors’]->add(‘user_email’, __($error, ‘my_bp_ban_domains’ ) );
return $result;
Source: http://stackoverflow.com/questions/14525400/ban-domain-extentions-buddypress

Just change $email = $result[‘user_email’] for the referrer.

What they’ve done there is take the dot out, explode the email address (in your case URL) and match it against the last item in the array.

Is there not another way around this though as it’s quite harsh to ban an entire extension.

Sponsor our Newsletter | Privacy Policy | Terms of Service