Register | Log in | RSS channel for codegravity.com homepage Bookmark!

284/2NEW projects | 71 services | 215 websites | 834/3NEW freelancers | 2126 topics | advertise



Login:



Forgot your password?
Forgot your username?
Create an account
JoomlaWatch Agent

Users

Most active users today from total of 107:
garikello, Peerke, jakkrit, dayanand, andrew_saber, giakhanh, mohalb, carmachhh, fguyon, dfireablaze, boho, phoeker, ozedfr, amoluca, JDev, blackie, ashish_php, Pascale, tinytim007, kostas13


19.9%United States United States
17.9%India India
9.3%Germany Germany
5.5%Russian Federation Russian Federation
4.4%United Kingdom United Kingdom
4.3%France France
4%Australia Australia
3.8%Netherlands Netherlands
3.8%Poland Poland
3.7%Italy Italy

Today: 942
Yesterday: 1402
This Week: 5232
Last Week: 8869
This Month: 2344
Last Month: 37593
Total: 117024


Partners:

HTML5, CSS3, SVG, tutorials

Freelance ColdFusion, Flex, PHP

Olejomalby, abstraktne obrazy

Camping Europe

WinAsm Studio

Vyšné Ružbachy

Sochy, Reštaurovanie

R.E.M.

Valid XHTML 1.0 Transitional

RSS feed:

Statistics:
Search Engine Genie Promotion Widget
Home

Email as Image in PHP

This is a class which is different than every other class you can find regarding coverting an email address to image.

This is because it uses the encryption of the email addresswhich is being passed to the script which renders the image. The renderer decrypts this parameter produces an image output.

 

 

Put both of these classes into root of your web:

 

 

ClassEmailAsImage.php


<?php
/**
 * ClassEmailAsImage - A class which inserts an email address as image instead of regular text to prevent spam
 *
 * @author Matej Koval http://www.codegravity.com
 *
 */
class ClassEmailAsImage {

    
/** this is left blank, only if you want to use type the host name manually, then change "" to "http://yourhost.com/directory/" */
    
private static $hostUrl "";

    
/** this is the key with which is the email address being encrypted, change it! */
    
private static $key "this is my long key which I have to change first";
    
    
/** this is a path to the script which renders the image, you can change it too */
    
private static $script "/emailAsImage.php";
    
    
/** paramter name which is being passed to the script producing image to decode the email address from */
    
private static $parameterName "email";


    
/**
     * Helper function which encodes the special characters like /,+,= to be included into the URL
     *
     * @param encoded string with special characters $input
     * @return encoded string with special characters replaced
     */
    
function encodeSlashPlus($input) {
        
$input str_replace("/","_SLASH_"$input);
        
$input str_replace("+","_PLUS_"$input);
        
$input str_replace("=","_EQ_"$input);
        return 
$input;
    }

    
/**
     * Helper function which decodes the special characters like /,+,= from URL
     *
     * @param encoded string with special characters replaced $input
     * @return encoded string with special characters 
     */
    
function decodeSlashPlus($input) {
        
$input str_replace("_SLASH_""/"$input);
        
$input str_replace("_PLUS_""+"$input);
        
$input str_replace("_EQ_""="$input);
        return 
$input;
    }

    
/**
     * Basic function which performs the encryption
     *
     * @param value to be encrypted $value
     * @return encryption result with special characters replaced
     */
    
function encrypt($value){
        
$text $value;
        
$iv_size mcrypt_get_iv_size(MCRYPT_3DESMCRYPT_MODE_ECB);
        
$iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);
        
$crypttext mcrypt_encrypt(MCRYPT_3DESClassEmailAsImage :: $key$textMCRYPT_MODE_ECB$iv);
        return 
ClassEmailAsImage :: encodeSlashPlus(base64_encode($crypttext));
    }

    
/**
     * Basic function which performs the decryption
     *
     * @param value to be decrypted, with special characters replaced $value
     * @return decryption result which returns the original value
     */
    
function decrypt($value){
        
$crypttext base64_decode(ClassEmailAsImage::decodeSlashPlus($value));
        
$iv_size mcrypt_get_iv_size(MCRYPT_3DESMCRYPT_MODE_ECB);
        
$iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);
        
$decrypttext mcrypt_decrypt(MCRYPT_3DESClassEmailAsImage::$key$crypttextMCRYPT_MODE_ECB$iv);
        return 
trim($decrypttext);
    }

    
/**
     * Function which uses the PHP GD library to render the image
     * which was taken from the parameter and decrypted to get the original value
     */
    
function renderImage() {
        
$parameterName ClassEmailAsImage::$parameterName;
        
$myText ClassEmailAsImage::decrypt($_GET[$parameterName]);
        
$myTextLen = (strlen($myText) * 10);
        
$safeemail imagecreate($myTextLen,20);
        
$backcolor imagecolorallocate($safeemail,255,255,255);
        
$textcolor imagecolorallocate($safeemail,0,0,0);
        
imagefill($safeemail,0,0,$backcolor);
        
Imagestring($safeemail,2,5,5,$myText,$textcolor);
        
header("Content-type: image/jpeg");
        
imagejpeg($safeemail);
    }


    
/**
     * Function called from the emailAsImage.php, which produces the URL to the image,
     * and appends a parameter with already encrypted email
     *
     * @param email to be encrypted $email
     * @return img HTML tag which points to the emailAsImage.php with encrypted email as parameter
     */
    
function render($email) {
        if (
ClassEmailAsImage::$hostUrl) {
            
$hostUrl ClassEmailAsImage::$hostUrl;
        } else {
            
$self rtrimdirname$_SERVER['PHP_SELF'] ), '/\\' ) ;
            
$hostUrl $_SERVER['HTTP_HOST'] . $self;

        }
        
$value ClassEmailAsImage::encrypt($email);
        
$url "http://".$hostUrlClassEmailAsImage::$script "?".ClassEmailAsImage::$parameterName."=".$value;
        
$output "<img src='".$url."' height='20' border='0'/>";
        return 
$output;

    }


}
?>


 

emailAsImage.php

 

<?php
require("ClassEmailAsImage.php");

ClassEmailAsImage::renderImage();

die();
?>

Produced HTML output:


Result on page:

Usage in your scripts

This is very simple:

require("ClassEmailAsImage.php");

ClassEmailAsImage::render($myEmailVariable);

 

You can get the complete source code in the Download section.

 

Comments  

 
-1 #1 matto 2010-04-29 16:12
test
Quote
 

Add comment


Security code
Refresh

No Tweets

Add URL of a programming website
register as a freelancer
submit your project
open freelance projects you can work on
webmaster resources
write paid blog posts about programming - tips and articles
bugs and features

Recommended: (advertise)
Download Joomlawatch 1.2.12



Advertise Here
-
Promote your services and get the new customers from the community of webmasters / programmers visiting CodeGravity.com


Freelancers, create paid articles
-
Looking for freelancers with experiences in Java to write paid articles on their experiences

Register as a Freelancer -
Submit your project experiences, programming languages and your other skills


Outsource your project
-
Submit your project description with all the requirements to more than 600 freelancers from around the world for FREE.

Green Geeks Hosting -
World's best selling green web hosting

FastDomain.com -
Fast Domain hosting. Hostmonster alternative. Also for $6.95/month.

HostMonster.com -
best cheap Joomla Web hosting. Website joomlawatchdemo.com is hosted by them with domain for $6,95/mo.



News from Twitter:
No Tweets
RSS Feeds:new

rss Freelance
rss Projects
rss Forum
rss Resources

Popular:
MathGuard
download mathguard
Random screenshot:

linoopz15.jpg


Poll

At what price would you purchase JoomlaWatch ad-free license?
 
Privacy policy | Advertise | Donate | Doucovanie Nemcina
Joomla Visitors Google Map
Loading map...
Joomla Visitors Google Map
Visitors Google Map Agent

Locations of visitors to this page


©2003-2010 Codegravity.com