Search code examples
phpjavascriptemaildecodeencode

Encode email with PHP then decode with JS


I'm working on a website that has many business profiles with their contact information which also include email addresses. Obviously I don't want to output the plain email addresses in the source due to spam. Could do mrsmith[at]gmail.com or obfuscate with ASCII but these solutions aren't ideal, not 100% foolproof.

The profiles do have a contact form but I also need to show the email addresses.

What I want to do is encode the emails with PHP and then decode with JS and create the anchor link dynamically. So I need an algorithm that's the same in PHP an JS if there is any...


Solution

  • I've now solved this with a form asking the user to fill in a value and submit it. If value i correct, show email address. Also set an 'isHuman' session parameter so others emails will just show by default.