PHP Classes
elePHPant
Icontem

File: MailCrypter.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Pablo Gazmuri  >  MailCrypter  >  MailCrypter.php  >  Download  
File: MailCrypter.php
Role: Class source
Content type: text/plain
Description: Allows for easy scrambling of email addresses in mailto links. This hides them from email harvesting programs, but will be descrambled in any javascript enabled browser.
Class: MailCrypter
Easily scramble mailto links to avoid harvesting.
Author: By
Last change: Changed File Role.
Date: 12 years ago
Size: 1,348 bytes
 

Contents

Class file image Download
<?php

// MailCrypter class
// Written by: Pablo Gazmuri on July 23, 2002
// This class writes scrambled mailto: links,
// keeping email addresses invisible to email
// harvesting programs.
// NOTE: Only tested in IE and Netscape 6


class MailCrypter{

    var
$links;
   
   
   
//this function adds a link and returns the scrambled link text
   
function addMailTo($address, $addlAttributes = ""){
       
$new = "";
       
       
$this->links[] = $address;
       
        for(
$i=0;$i<strlen($address);$i++){
           
$new .= chr(ord(substr($address, $i, 1)) - 1);
        }
       
        return
"<a id=\"link".(count($this->links)-1)."\" href=\"mailto:$new\" $addlAttributes >$new</a>";
    }
   
   
   
//this function echos the javascript code to descramble the links
   
function writeScript(){
   
    echo
"\n\n<script language=\"JavaScript\">
        <!--hide from older browsers\n"
;
       
   
       
    echo
"
        function ConvLink(link){
            var temp='';
            var i;
            for(i =0;i<link.href.length;i++){
                if (i>6){
                    temp = temp + String.fromCharCode(link.href.charCodeAt(i)+1);
                }else{
                    temp = temp + link.href.charAt(i);
                }
            }
            link.href = temp
            link.innerHTML = temp.substring(7);
               
        }\n"
;
       
        for(
$i=0; $i<count($this->links);$i++){ echo "
        ConvLink(document.getElementById('link
$i'));\n";}
       
        echo
"-->\n</script>";
   
   
   
    }
   

}

?>