Last active
August 29, 2015 14:12
-
-
Save chrisblakley/cdb3fe68cf7090d3bae5 to your computer and use it in GitHub Desktop.
Spambot prevention snippets using .htaccess and PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SetEnvIfNoCase Referer semalt.com spambot=yes | |
| SetEnvIfNoCase Referer econom.com spambot=yes | |
| SetEnvIfNoCase Referer buttons-for-website.com spambot=yes | |
| SetEnvIfNoCase Referer ilovevitaly.com spambot=yes | |
| SetEnvIfNoCase Referer ilovevitaly.ru spambot=yes | |
| SetEnvIfNoCase Referer darodar.com spambot=yes | |
| SetEnvIfNoCase Referer 7makemoneyonline.com spambot=yes | |
| SetEnvIfNoCase Referer myftpupload.com spambot=yes | |
| SetEnvIfNoCase Referer priceg.com spambot=yes | |
| Order allow,deny | |
| Allow from all | |
| Deny from env=spambot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action('init', 'nebula_spambot_prevention'); | |
| function nebula_spambot_prevention(){ | |
| //List of known spambots. The dots allow for any TLD to trigger with fewer false-positives. | |
| $known_spambots = array('semalt.', 'ilovevitaly.', 'darodar.', 'econom.', 'makemoneyonline.', 'buttons-for-website.', 'myftpupload.', 'co.lumb', 'iskalko.', 'o-o-8-o-o.', 'o-o-6-o-o.', 'cenoval.', 'priceg.', 'cenokos.', 'seoexperimenty.', 'gobongo.', 'vodkoved.', 'adcash.', 'websocial.', 'cityadspix.', 'luxup.', 'ykecwqlixx.', 'superiends.', 'slftsdybbg.', 'edakgfvwql.', 'socialseet.', 'screentoolkit.', 'savetubevideo.'); | |
| if ( isset($_SERVER['HTTP_REFERER']) && contains(strtolower($_SERVER['HTTP_REFERER']), $known_spambots) ) { | |
| header('HTTP/1.1 403 Forbidden'); | |
| die; | |
| } | |
| if ( isset($_SERVER['REMOTE_HOST']) && contains(strtolower($_SERVER['REMOTE_HOST']), $known_spambots) ) { | |
| header('HTTP/1.1 403 Forbidden'); | |
| die; | |
| } | |
| } | |
| function contains($str, array $arr) { | |
| foreach( $arr as $a ) { | |
| if ( stripos($str, $a) !== false ) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment