Simple, emphasize SIMPLE, PHP/Javascript email addr hiding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LVZ
Forum Newbie
Posts: 5
Joined: Mon Oct 03, 2005 1:04 pm
Location: Las Vegas

Simple, emphasize SIMPLE, PHP/Javascript email addr hiding

Post 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?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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)
LVZ
Forum Newbie
Posts: 5
Joined: Mon Oct 03, 2005 1:04 pm
Location: Las Vegas

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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. ;)
Post Reply