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
CODE
<?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, Konqueror
xmlHttp = new XMLHttpRequest();
} catch (e){
// Internet Explorer
try {
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
}
?>
$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, Konqueror
xmlHttp = new XMLHttpRequest();
} catch (e){
// Internet Explorer
try {
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.- JavaScript-only version.
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.


