RomanWare  

Go Back   RomanWare > Web Design > PHP/MYSQL

PHP/MYSQL Discus The PHP language for web design.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-12-2009, 10:21 PM
Jon's Avatar
Jon Jon is offline
Newbie
 
Join Date: Apr 2009
Posts: 3
Rep Power: 0
Jon is on a distinguished road
Default script to check for spammers

due to the number of spammers constantly trying to get into the forum, etc, i have made a script that checks a given ip, email or both, against a spam database. good to use when someone tries to register a new account.

Code:
require_once('socket.php');
function is_spam_bot($spam_ip='',$spam_email=''){

  /* this will check for just an ip, or just an email address, or both */

  if ($spam_email!='')
    if (get_spam_element('email='.$spam_email)) return TRUE;

  if ($spam_ip!='')
    if (get_spam_element('ip='.$spam_ip)) return TRUE;

  return FALSE;

}

function get_spam_element($s){

  $socket=new Socket();
  if (!$socket->connect('www.stopforumspam.com',80)) return FALSE;

  $packet='GET /api?'.$s.' HTTP/1.0'.chr(13).chr(10).
          'Host: '.$socket->server.chr(13).chr(10).chr(13).chr(10);

  $socket->send($packet);

  if (strpos($socket->receive(),'<appears>yes</appears>')!==false) return TRUE;

  return FALSE;

}
Code:
<?php

/* Socket Wrapper
  by Sharp Dressed Codes
  http://sharpdressedcodes.com
  12th September, 2008
*/


class Socket {

var $server='';
var $port=0;
var $type='TCP';
var $handle=NULL;

function connect($server='',$port=0){

  if ($server!='') $this->server=$server;
  if ($port>0) $this->port=$port;
  if (!is_null($this->handle)) close();

  $this->handle = socket_create(AF_INET, SOCK_STREAM, ($this->type=='TCP'?SOL_TCP:SOL_UDP));

  if (!@socket_connect($this->handle, $this->server, $this->port)){
    return FALSE;
  } else {
    return TRUE;
  }

}

function close(){
  if (!is_null($this->handle)){
    @socket_close($this->handle);
    $this->handle=NULL;
  }
  return TRUE;
}

function send($data=''){
  if (!is_null($this->handle)){
    socket_send($this->handle, $data, strlen($data), 0);
    return TRUE;
  }
  return FALSE;
}

function receive($close_data=''){
  $buffer='';
  $packet='';
  while (socket_recv($this->handle, $packet, 2048, 0) > 0){
    $buffer .= $packet;
    if ($close_data!=''){
      if (strpos($buffer,$close_data)) break;
    }
  }
  return $buffer;
}

}

?>
it originally used fopen to check the database, but my gay hosting decided to remove that function, so i had to resort to using a socket.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:06 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
©RomanWare 2009
BP-Grey Style by Bluepearl Design - Ver2.1