PHP Classes
elePHPant
Icontem

File: lutaspam.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of David Ferreira  >  Luta Spam  >  lutaspam.class.php  >  Download  
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
Author: By
Last change: Now it replaces the @ and . for images, for better security against spam bots
Date: 6 years ago
Size: 3,088 bytes
 

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($filtrar, strrpos($filtrar, "@"), strlen($filtrar) - 1);
               
$nome = substr($filtrar, 0, strrpos($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;
    }
}
?>