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.