Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Php - Ajax: E-mail Protection, Clickable Image
truefusion
post Dec 11 2007, 09:14 PM
Post #1


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,887
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



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
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" />
&lt;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.
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.

This post has been edited by truefusion: Dec 15 2007, 08:18 AM
Go to the top of the page
 
+Quote Post
shadowx
post Dec 12 2007, 10:20 AM
Post #2


A clever man learns from his own mistakes, a WISE man learns from those of OTHERS
*********

Group: [HOSTED]
Posts: 884
Joined: 12-April 06
From: Essex, UK
Member No.: 21,719



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
Go to the top of the page
 
+Quote Post
truefusion
post Dec 12 2007, 11:56 AM
Post #3


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,887
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



QUOTE(shadowx @ Dec 12 2007, 05:20 AM) *
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.

This post has been edited by truefusion: Dec 15 2007, 08:19 AM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Scrolling Images?(5)
  2. Ajax - A New Technology(10)
  3. Data Structures -- Binary Tree -- Mirror Image(0)


 



- Lo-Fi Version Time is now: 7th August 2008 - 11:46 PM