Jump to content
xisto Community
Sign in to follow this  
truefusion

Php - Ajax: E-mail Protection, Clickable Image

Recommended Posts

Description

Concept sparked by the following topic: Email Address Protection From Spam Bots. The idea is to have an image, when clicked on, turn into selectable text. The e-mail is encoded, and that encoding is sent to the server through AJAX to be decoded via PHP. After it is decoded, it gets sent back to be inserted into a text field which is automatically selected upon clicking the image. I have decided to keep things limited to one page for now, where the concept can be easily seen.

 

Code


 

if ($get != ""){

echo "mailto linenums:0'><?php$get = $_GET['code'];if ($get != ""){echo "mailto: ".base64_decode($get);} else {?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;<html xmlns="http://www.w3.org/1999/xhtml/; xml:lang="en" lang="en"><head><title>untitled</title><meta http-equiv="content-type" content="text/html;charset=utf-8" /><script>function ajaxFunction(id, code){var xmlHttp;try {// Firefox, Opera, Safari, KonquerorxmlHttp = new XMLHttpRequest();} catch (e){// Internet Explorertry {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e){try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (e){alert("Your browser does not support AJAX!");return false;}}}xmlHttp.onreadystatechange = function(){if(xmlHttp.readyState == 4){document.location.href = xmlHttp.responseText;}}xmlHttp.open("GET", "antispam_email.php?code="+code, true);xmlHttp.send(null);}</script></head><body><noscript>In order to select the e-mail you require JavaScript enabled.</noscript><span id="email_link"><a href="java script: ajaxFunction('email_link', '<?php echo base64_encode("email@domain.com"); ?>');">Click Here To E-mail Me</a></span></body></html><?php}?>


Preview

 

Soon to Come

Dynamic image generation. (Image not needed anymore.)

JavaScript-only version.

Changes

Got rid of the image, and turned it into a link. Made it possible to load up the e-mail program without leaving the page.

Edited by truefusion (see edit history)

Share this post


Link to post
Share on other sites

Very nice! I can see many applications here for those who want to use their email address as a point of contact. Dynamic image generation would be a great bonus as that way it could be integrated into websites with many users who need to use their email address as a point of contact, EG profile sites and the like where many email addresses will be saved by this simple idea. Would i be right in assuming this code could be modified to show a MAILTO link instead of the textbox? That culd be even more useful for webmasters who use their email but want to give the user as much ease of use as possible.Brilliant idea and code there, i can see it helping a lot of people

Share this post


Link to post
Share on other sites

Would i be right in assuming this code could be modified to show a MAILTO link instead of the textbox?

Yes, it's possible to do that, and i have thought about it, but i figured, why have the user click twice? Instead, i've been trying to figure out a way to make it load in a way as if you've already clicked on a mailto link without leaving the page, you know? But i'm not quite sure how to go about it.—made it possible. Edited by truefusion (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.