PHP Classes
Icontem

File: MailCrypter.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 Pablo Gazmuri  >  MailCrypter  >  MailCrypter.php  
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.
 

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$i1)) - 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>";
    
    
    
    }
    

}

?>

 
  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