Register | Log in | Password |

365 projects | 71 services | 215 websites | 1073 freelancers | 2755 topics | advertise


Purchase JoomlaWatch:
30 day money-back guarantee
Read more...
9 EUR lifetime license
Buy Now

15 EUR lifetime license
Buy Now
(nofollow link from sponsors page)

Login:

23.4%United States United States
15.4%India India
7.3%Russian Federation Russian Federation
7.1%Colombia Colombia
6.1%Germany Germany
5.2%United Kingdom United Kingdom
4.4%Poland Poland
3.5%Netherlands Netherlands
3.1%France France
2.9%Canada Canada

Today: 165
Yesterday: 1413
This Week: 8228
Last Week: 10267
This Month: 4868
Total: 28182

Users

Most active users today from total of 9:
mlewis, Gomjerk, swaffel, specialone, leoaraujo, strategist, hanji, Denclub, fddeltenre
About JoomlaWatch:
JoomlaWatch is popular joomla visitor tracking and live stats component. It provides several features such as spam blocking, goals tracking, charts, nightly email reports, latest visit map, interactive HTML5 traffic flow graph and many other useful functionalities, which will help you to optimize your site.
RSS Feeds:

rss Freelance
rss Projects
rss Forum
rss Resources

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  

 
0 #1 matto 2010-04-29 15:12
test
Quote
 

Add comment


Security code
Refresh


no license?

Recommended: (advertise)
Joomlawatch 1.2.17 Demo (PRO: 9/15 EUR)
Download Joomlawatch 1.2.17 (PRO: 9/15 EUR)

Rate this extension ...


Stay in touch:

New article about JoomlaWatch Live Stats feature: (link)
16 hours ago from web

Tested versions 1.2.12 FREE, 1.2.17 PRO, 1.2.18 BETA on Joomla 2.5 and older Joomla 1.5 - confirmed to work on both Joomla versions

Small installer fixes - added JoomlaWatch compatibility with Joomla 2.5

New article on JoomlaWatch Traffic Flow feature: (link) ... All features of JoomlaWatch will be documented this way.

Another minor fixes for version 1.2.17 and 1.2.18, added functionality to display only changed values in SEO report - important keyprases
2 weeks ago from web

Minor fixes for JoomlaWatch version 1.2.17 (language files), you can find the latest package in customer zone ((link)
2 weeks ago from web

If you'd like to help with testing of the latest 1.2.18 BETA with new features (Joomla/Wordpress),please add me on skype: matto3c.Thank you!
3 weeks ago from web

New article on JoomlaWatch SEO (Search Engine Optimization) report functionality - (link)

JoomlaWatch 1.2.18 is out now! Features new click heatmap feature, SEO report - how people find you on google, and many other improvements

Reorganized the menu items. Now you'll be able to easily find most requested links

JoomlaWatch 1.2.18 BETA now ready! Main features: - Heatmap integration - SEO reports - Anti-spam section visualization (link)

Fixed one issue: no unique visits recorded; PHP $_SERVER['REMOTE_ADDR'] doesn't always return remote IP address! using HTTP_X_FORWARDED_FOR

Christmas Special - 19% OFF from all licenses until 25th of December 2011

JoomlaWatch Heatmap functionality nearly done. Works with all client resolutions. Will be available in next version. (link)

Simple customer zone - (link) is now ready. Users who purchased the PRO version can now download newest version from there.

Because of the problems with payments and forwarding. We are using (link) service to deliver you the files after purchase.

Tracking Expenses from SMS android application is now published on android market :) and it's completely free !

(link) user information now protected with UserCrypt 1.1

UserCrypt version 1.1 released: Added query log, jos_users decryption on database interceptor plugin deactivation (link)

Timezone issue now fixed. Tested on canadian server which has hosting in the USA. Also module class suffix parameter now works for J1.7



Partners:
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
Privacy policy | Advertise | Donate

Locations of visitors to this page


©2003-2010 Codegravity.com