<?php
/*=============================
C:\xampp\htdocs\email\index.php or http://localhost\email\index.php
PHP Script to present an Email link created from an email address as an effort to avoid Spam Bots and page-scrapers with the tooltip text disguised using [ AT ] and [DOT] and maito: value obscured as htmlentities (hex values).

Notes:
1.) $text could be from a database call or from a value in a Config file. Font-face and size, also.
2.) Replace : href= : with the appropriate page link if you use a Contact Form page rather than the mailto: protocol.
3.) Does not check for a valid email address or the format of the address.
4.) CSS styling hooks

Copyright 2007 by the Script Author: jlhaslip [ AT ] yahoo [ DOT ] ca c/o http://www.jlhaslip.com

This program is free software: you can redistribute it and/or modify it under the terms of the Creative Commons Licence as follows: http://creativecommons.org/licenses/by-sa/2.5/ca/
This Script is licenced under a Creative Commons Licence on an Attribution and Share-alike basis.
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.
This Copyright information may not be altered and must be included in Derivative Works.

<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/ca/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/2.5/ca/88x31.png" /></a>This script is licenced under a<a rel="license" href="$">Creative Commons Licence</a> Some Rights Reserved.

==============================*/
$debug 1// set flag = 1 while testing, flag = 0 for live site
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>
            Email Link Creator
        </title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta http-equiv="content-style-type" content="text/css" />
        <meta http-equiv="keywords" content="Email obfusction, obfuscate, spam protection, disguise email adderss" />
        <meta http-equiv="description" content="Hide your email address from Spam bots by encoding and disguising the mail to link on your page so they can't read it, but people can. " />
        <meta http-equiv="reply-to" content="jlhaslip@yahoo.ca" />
        <meta http-equiv="author" content="Jim Haslip" />
        <style type="text/css">
/*<![CDATA[*/
        /* =======
        Template CSS
        ============*/
        * html { margin:0; padding:0;}
        html, body { height: 100%; }
        #wrapper { min-height: 100%; }   /* div you want to stretch */
        body { margin:0 auto; text-align:center; background-color: #eeddbb; }
        p { margin: .25em; padding:.25em; text-align:left }
        #wrapper { margin: 0 auto; width: 1000px; background-color: #ffeecc; border: 1px solid #666666; }
        #header { margin: 1em 0; text-align:center; border-bottom: 1px solid #666666; }
        #header h1 { margin: 1em 0; }
        #page_contents { padding: 1em; margin: 0 auto;  text-align: center; }
        h2 { margin: 0 auto; }
        #footer { margin: 1em auto; padding: 1em; text-align:center; border-top: 1px solid #666666; }
        #footer a { margin: 1em auto; padding: .15em; }
        /* =======
        Page specific CSS Below this line
        ============*/
<!--  localhost\email_image\checking2.php  C:\xampp\htdocs\email_image\checking2.php -->
        form { margin: 0 auto; text-align:center; width: 450px; }
        #form_div { width: 450px; margin: 0 auto; }
        fieldset { width: 400px; clear: left;  background-color: #transparent; }
        textarea { width: 85%; }
        /*]]>*/
        </style>
<!--[if lte IE 6]>
<style type="text/css">
#wrapper {
height: 100%;
}
</style>
<![endif]-->
    </head>
    <body>
        <div id="wrapper">
            <div id="header">
                <h1>
                    Conceal Your Email Address
                </h1><!-- header -->
            </div><!-- header -->
            <div id="page_contents" style=" padding: 1em; margin: 0 auto; ">
                <h2>
                Create an Obfucated Email Link
                </h2>
<div id="form_div" >
<form action="<?php $_SERVER['PHP_SELF'?>"  method="post" enctype="multipart/form-data">
     <fieldset >
        <legend><strong>All fields are required</strong></legend>
     <!-- email input -->
        <div >
            <label for="email" >
                <span >Email:</span>
            </label>
            <input type="text" name="email" id="email"  class="inputText" size="30" maxlength="100" value="&#x6a;&#x6c;&#x68;&#x61;&#x73;&#x6c;&#x69;&#x70;&#x40;&#x79;&#x61;&#x68;&#x6f;&#x6f;&#x2e;&#x63;&#x61;" />
        </div>
   </fieldset>
    <fieldset  >
        <legend><strong>Submit</strong></legend>
            <div >
                <div class="hidden">
                    <input type="submit" class="inputsubmit" value="Request &raquo;" />
                    <input type="hidden" name="submit" value="true" />
                </div>
            </div>
    </fieldset>
    <?php
if (isset($_POST['submit']) ) {                        //  submitted
        
$text $_POST['email'];                                // text for the image. Spaces will be removed
} else {                                                    // not submitted
        
$text "jlhaslip@yahoo.ca";                // text for the image. input your email here...Spaces will be removed.
    
}
?>
        <fieldset >
            <legend><strong>Sample of your Email Link</strong></legend>
    <?php
email_obfuscate
$text );            // call the function to echo the email link
    
hexentities$string ); // $text in, $encoded out
?>
        </fieldset>
 <fieldset >
        <legend><strong>Cut and Paste this Information</strong></legend>
     <!-- email input -->
      <div>
        <textarea rows="8" cols="40" readonly = "readonly" >
<?php
        
echo $encoded;
?>
        </textarea>
        <p>Originally posted as a tutorial here: <a href="http://www.trap17.com/forums/index.php?showtopic=52408&st=0&gopid=351546&#entry351546" title="email concealment script on the Trap17" >here</a></p>
        <p>Download the script <a href="http://www.jlhaslip.trap17.com/samples/email/index.phps" title="email concealment script download" >here</a></p>
        </div>
    </fieldset>
 </form>
        </div >
            </div>
            <div id="footer" style="clear:both;">
                <a href="http://validator.w3.org/check?uri=referer">validate the xhtml</a>&nbsp;&nbsp;&copy;&nbsp;
                <a href="http://jlhaslip.com/">jlhaslip.com</a>&nbsp;&nbsp;
                <a href="http://jigsaw.w3.org/css-validator/">validate the css</a>&nbsp;&nbsp;
                <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/ca/"></a>This script is licenced under a<a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/ca/">Creative Commons Licence</a> Some Rights Reserved.&nbsp;&nbsp;
            </div><!-- footer -->
        </div><!-- wrapper -->
    </body>
</html>
<?php
function email_obfuscate($text) {
        
// defaults to these values if undefined in the script
        
global $text$email$encoded$string ;
        
$text trim($text);                         //trim the text value
        
$text str_replace(' '''$text);         //replace {spaces}
        
$text str_replace('&nbsp;'''$text);     //replace {html spaces}
        
$text clean_user_input($text);
        if (
stristr($text'Bad value')) {
                echo 
$text;
                } else {
    
code_mail$text );                                 // $text in, $email out
    
hexentities$text ); // $text in, $encoded out
        
$mailto_text "&#x4d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&#x3a;";
        
$string '<a href="'$mailto_text $encoded '" title="send an email to:' $email '">' $encoded '</a>';
        echo 
'<div id = "email_id" >';
        echo 
$string;
        echo 
'</div>';
        }
    }
function 
code_mail$text ) { // for visual display of email address in tooltip
    
global $text$email;
        
$email str_replace'.'' [ DOT ] '$text); //replace . with DOT
        
$email str_replace'@'' [ AT ] '$email); //replace @ sign with AT
        
return $email;
}
function 
hexentities($str) { // encodes the text into 'html entity' format for use in the mailto:
    
global  $encoded;
    
$encoded '';
    for(
$i 0$i strlen($str); $i++) {
        
$encoded .= '&#x'.bin2hex(substr($str$i1)).';';
    }
    return 
$encoded;
}


/* ************************************************************************
* based on a function from Larry Ullman at dmcinsights.com
* as found here: http://www.dmcinsights.com/phorum/read.php?6,28810
*************************************************************************** */

function clean_user_input($value) {

    
// Check for bad values:
    
if (stristr($value'content-type')) return 'Bad value ... try without the content type';
    if (
stristr($value'bcc:')) return 'Bad value ... try without the bcc';
    if (
stristr($value'to:')) return 'Bad value ... try without the to';
    if (
stristr($value'cc:')) return 'Bad value  ... try without the cc';
    if (
stristr($value'href')) return 'Bad value ... try without the href';

    
// Strip quotes, if Magic Quotes are on:
    
if (get_magic_quotes_gpc()) $value stripslashes($value);

    
// Replace any newline characters with spaces:
    
$value str_replace(array( "\r""\n""%0a""%0d"), ' '$value);

    
// Replace any htmlentities
    
$value htmlentities($valueENT_QUOTES"UTF-8" );

    
// Return the value:
    
return trim($value);

}

?>