PHP Classes
Icontem

File: lutaspam.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of David Ferreira  >  Luta Spam  >  lutaspam.class.php  
File: lutaspam.class.php
Role: Class source
Content type: text/plain
Description: The class itself
Class: Luta Spam
Encode e-mail addresses to prevent harvesting
 

Contents

Class file image Download
<?php
/*******************************************************************************
*   lutaspam v1.2 is a PHP class to make harder for spambots to get emails
*   Copyright (C) 2008  David Sopas Ferreira <coder at davidsopas dot com>
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/

class lutaspam
{
    
// Define images for @ and .
    
private $image_at "at.jpg";
    
private $image_dot "dot.jpg";

    
// Check DNS records to Internet host name of the given email
    
public function verificadns($email)
    {
        list(
$utilizador$dominio) = split('@'$email);
        if (!
checkdnsrr($dominio'MX'))
        {
            
// Domain valid
            
return false;
        } else
        {
            
// Domain not valid
            
return true;
        }
    }

    
// Function that code and decode the email variable
    
public function filtra($filtrar$opcao)
    {
        
$at $this->image_at;
        
$dot $this->image_dot;
        if (
$opcao == 0)
        {
            
// Condition to check the format of the email address
            
if (preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix",
                
$filtrar) && $this->verificadns($filtrar) == true)
            {
                
// Splits the email in two parts (username and domain)
                
$dominio substr($filtrarstrrpos($filtrar"@"), strlen($filtrar) - 1);
                
$nome substr($filtrar0strrpos($filtrar"@"));

                
// Replaces the . and @ for respective image
                
$dominio str_replace(".""<img src='$dot' border='0'>"$dominio);
                
$dominio str_replace("@""<img src='$at' border='0'>"$dominio);
                
$nome str_replace(".""<img src='$dot' border='0'>"$nome);
                
$filtrado $nome $dominio;

            } else
            {
                
$filtrado "ERROR: email not valid!";
            }

        } elseif (
$opcao == 1)
        {
            
// Replaces the coded email for the original ones
            
$filtrado str_replace("<img src='$at' border='0'>""@"$filtrar);
            
$filtrado str_replace("<img src='$dot' border='0'>""."$filtrado);
        } else
        {
            
$filtrado "ERROR: option not present!";
        }
        return 
$filtrado;
    }
}
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products