Page 1 of 1

Simple, emphasize SIMPLE, PHP/Javascript email addr hiding

Posted: Tue Oct 04, 2005 5:00 pm
by LVZ
It is very easy in PHP to make a low security email address code-or-decode obfuscator:

strrev(str_rot13(email_address));

On the Javascript side (used to access HTML form elements), however, there don't seem to be any similar built-in functions.

I know this is a PHP forum, but does anyone know an easy method both in PHP and Javascript for simple obfuscation to avoid spammer bots? Perhaps flipping string bits or something?

Posted: Tue Oct 04, 2005 6:05 pm
by Ambush Commander
You could always build them (the javascript functions) yourself.

Here are some common ways of munging email addresses:

1. Not giving the email address at all. Rather, provide a contact form that people can use.

2. Change user@domain.com to user AT domain DOT com

3. Change user@domain.com to user@domain.nospam-removethis.com

4. Put a bunch of hexadeciimal things in JavaScript and have that translate it out (Smarty has an implementation of this)

Posted: Wed Oct 05, 2005 1:04 am
by LVZ
On the Javascript side, I modified (sloppier but much more compact) some code I found:

Code: Select all

<script language="Javascript">
function enCode(addr){ var kode, gunk="", L=addr.length;
  for (var x=0;x<L;x++) { kode = addr.charCodeAt(x)+L; gunk+=kode; if(x<L-1) gunk+="|"; } return gunk;
}
function deCode(gunk){ var kode,oneC, kStr=new String(gunk), kArray=kStr.split('|'), L=kArray.length, orig="";
  for (var x=0;x<L;x++) { kode=kArray[x]; oneC=String.fromCharCode(kode-L); orig+=oneC; } return orig;
}
</script>
The Javascript deCode function will work well for manipulating HTML FORM fields.

Now I just have to translate the enCode function into PHP.

Posted: Wed Oct 05, 2005 12:05 pm
by Skara

Code: Select all

print("<script type='javascript'><!--\n".
      "var string = ''\n");
$string = "hello";
$string = explode($string);
foreach ($string as $letter) {
    print("string += '$letter';\n");
}
print("document.write(string); // or whatever".
      "//--></script>");
so that...

Code: Select all

var string = '';
string += 'h';
string += 'e';
string += 'l';
//...
That's about as simple as it gets. ;)