Jump to content

PHP code to disable spammer registration tries


DMITRII LODIAKOV

Recommended Posts

This is file spammer.php file in forum directory

<?php
  2
  3 if(strtolower($_REQUEST['app']) == 'core' && strtolower($_REQUEST['module']) == 'global' && strtolower($_REQUEST['section']) == 'register') {
  4
  5 define("MAX_POST_COUNT", 3);
  6 define("POST_DELAY", 150);
  7 define("BAN_TIME", 7200);
  8
  9 include('conf_global.php');
 10
 11 $mysqli = new mysqli($INFO['sql_host'], $INFO['sql_user'], $INFO['sql_pass'], $INFO['sql_database']) or die("Sql Error");
 12
 13 if(mysqli_connect_errno()) {
 14     printf("Connect failed: %sn", mysqli_connect_error());
 15         exit();
 16 }
 17
 18 $ip = ip2long($_SERVER['REMOTE_ADDR']);
 19
 20 $query = "SELECT LAST_POST_TIME, POST_COUNT, BLOCKED FROM SPAMMER_IPS WHERE IP = $ip;";
 21 $result = $mysqli->query($query);
 22
 23 if($mysqli->affected_rows > 0) {
 24     $row = $result->fetch_assoc();
 25
 26     $current_time = time();
 27     $last_post_time = strtotime($row['LAST_POST_TIME']);
 28
 29     $time_diff = $current_time - $last_post_time;
 30
 31     if($row['POST_COUNT'] >= MAX_POST_COUNT) {
 32         if($time_diff < BAN_TIME) {
 33             $query = "UPDATE SPAMMER_IPS SET LAST_POST_TIME = NOW(), POST_COUNT = POST_COUNT + 1 WHERE IP = $ip;";
 34             $mysqli->query($query);
 35
 36             header('HTTP/1.0 404 Not Found');
 37             exit;
 38         }
 39         else {
 40             $query = "DELETE FROM SPAMMER_IPS WHERE IP = $ip;";
 41             $mysqli->query($query);
 42         }
 43     }
 44     else {
 45         if($time_diff < POST_DELAY) {
 46             $query = "UPDATE SPAMMER_IPS SET LAST_POST_TIME = NOW(), POST_COUNT = POST_COUNT + 1 WHERE IP = $ip;";
 47         }
 48         else {
 49             $query = "DELETE FROM SPAMMER_IPS WHERE IP = $ip;";
 50         }
 51
 52         $mysqli->query($query);
 53     }
 54 }
 55 else {
 56     $query = "INSERT INTO SPAMMER_IPS (IP, POST_COUNT) VALUES ($ip, 1);";
 57     $mysqli->query($query);
 58 }
 59
 60 mysqli_close($mysqi);
 61
 62 }
 63
 64 ?>

This is SPAMMER_IPS table

DROP TABLE IF EXISTS `SPAMMER_IPS`;
CREATE TABLE IF NOT EXISTS `SPAMMER_IPS` (
  `IP` int(4) unsigned NOT NULL,
  `LAST_POST_TIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `POST_COUNT` int(2) unsigned NOT NULL DEFAULT '0'
  PRIMARY KEY (`IP`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

And the last one you need to add this line

include('spammer.php');

in forum/index.php

  1 <?php
  2 /**
  3  * <pre>
  4  * Invision Power Services
  5  * IP.Board v3.4.6
  6  * Main public executable wrapper.
  7  * Set-up and load module to run
  8  * Last Updated: $Date: 2013-02-26 08:08:06 -0500 (Tue, 26 Feb 2013) $
  9  * </pre>
 10  *
 11  * @author      $Author: mark $
 12  * @copyright   © 2001 - 2009 Invision Power Services, Inc.
 13  * @license     http://www.invisionpower.com/company/standards.php#license
 14  * @package     IP.Board
 15  * @link        http://www.invisionpower.com
 16  * @version     $Rev: 12025 $
 17  *
 18  */
 19
 20 include('spammer.php');
 21
 22 define( 'IPB_THIS_SCRIPT', 'public' );
 23 require_once( './initdata.php' );/*noLibHook*/
 24
 25 require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );/*noLibHook*/
 26 require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );/*noLibHook*/
 27 ipsController::run();
 28
 29 exit();

And after it spammers won't waste your traffic.

Yeah. And it's working only with MySQL. It's just quick fix for stop spammer registration tries.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...