stefan and zogo small Help Stefan Campaign
If you can spare $1 then help support this site and change someone's life forever? Learn how and why on the Help Stefan campaign page.

Email Shuffling Script

Introduction

The only problem with the JavaScript e-mail obfuscating script presented already is that you have to embed JavaScript into your web page for it to work. I've been looking for an alternative and I have found one in a php script that obfuscates your email address by re-shuffling and then uses plain CSS to make it apear in the web page as a normal email address though the underlying code is obfuscated and your email cannot be harvested by email harvesters.

The code for generating the obfuscated email address is based on that of Daniel Hjerth whith a few changes of my own. This code is given below:

    function mailshuffle( $mail ) {

       $output = array();

       $element = "span";
       $spacing = 'round($x/1.75, 2)';
       $class = "mstag";
       $spacing_attribute = "left";
       $spacing_type = "em";

          for ($x=0; $x<strlen($mail); $x++)
          {
             eval('$i = '. $spacing . ";");
             $output[] =
              "<{$element} class='{$class}' style='{$spacing_attribute}:{$i}{$spacing_type};'>".htmlentities($mail{$x})."</{$element}>";

          }

          if(function_exists("shuffle_variable"))
          {
             shuffle_variable(&$output);
          }
          else
          {
             mt_srand( (double) microtime() * pow(10,5) );
             $array_size = count($output);
             for($x=0; $x<$array_size; $x++)
             {
                $n = mt_rand(0, $array_size - 1);
                $p = $output[$n];
                $output[$n] = $output[$i];
                $output[$i] = $p;
             }
          }

             return "<div style='position:absolute;'>".implode("",$output)."</div>";
    }

To get this function to work you will need to call it with something like: echo "<p>".mailshuffle($Email)."</p><br/><br/>"; which both calls the function with your email address and prints the result to your web page.

Remember, however, that if you want to print out the email address (and for it to actually look like a real email address in your browser) you will need to add the following CSS code either to your CSS file or to your HTML page. I actually add this to the HTML page itself just before the end of the </head> tag:

<style type="text/css">
.mstag{position:absolute; font-family:monospace;margin:0.45em;background-color:#fcc};
</style>

You now have everything you need to deploy the php code on your own website. But if you don't want to deploy the entire code you can use the form below to generate the code that will allow you to generate code to obfuscate your own e-mails.

Protect your email addresses

To use the code generated simply copy and paste into your own web page but remember to add the CSS code to the page or all you will see is gibberish! An example of what your encoded email looks like to a visitor to your site is given beneath the code that's been generated.