note 44882 deleted from reserved.variables by sp
| From: | sp@php.net | Date: | Thu, 19 Aug 2004 04:27:30 +0000 |
| Subject: | note 44882 deleted from reserved.variables by sp | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79995@lists.php.net to get a copy of this message | ||
Note Submitter: potramihai at yahoo dot com
----
Many times I wished to use a way to enable mailto: links with a spam
protection too.
I just came up with a script using the $_SERVER predefined array variable.
In my code I used a link to a file safemail.php like this
index.php :
<?php
echo("<HTML>");
echo("<BODY>");
$_eadr=base64_encode("mymail@domain.com");
echo("<A Href=\"safemail.php?address=\"".$_eadr."\"
Target=\"email_frame\"> Click here to send an e-mail </A>");
echo("<IFRAME Name=\"email_frame\" Src=\"blank\"
style=\"position:absolute;visibility:hidden;\"></IFRAME>");
echo("</HTML>");
?>
The <IFRAME> will mask the entire process.
safemail.php :
<?php
$_referer=parse_url(dirname($_SERVER["HTTP_REFERER"]));
$_ex_svn=explode(".",$_SERVER["SERVER_NAME"]); // Extracting the current domain
$_ex_svn_nr=count($_ex_svn);
if($_ex_svn_nr>=2) {
$_svn=$_ex_svn[$_ex_svn_nr-2].".".$_ex_svn[$_ex_svn_nr-1];
} else {
$_svn=$_ex_svn;
}
if($_referer["path"]=="") {
$_referer["path"]="/"; //this way root scripts will work too.
}
$_ex_cdh=explode(".",$_referer["host"]); // Extracting the caller domain
$_ex_cdh_nr=count($_ex_cdh);
if($_ex_cdh_nr>=2) {
$_cdh=$_ex_cdh[$_ex_cdh_nr-2].".".$_ex_cdh[$_ex_cdh_nr-1];
} else {
$_cdh=$_ex_cdh;
}
if((dirname($_SERVER["PHP_SELF"])==$_referer["path"]) AND ($_cdh==$_svn) AND
(isset($_GET["address"]))) {
header("Location: mailto:".base64_decode($_GET["address"]));
} else {
echo("Spam protection active");
}
?>
This way spam bots will get a dead end when trying to harvest the e-mail address, as their location
is different.
Also you can use only $_cdh==$_svn in the if structure.
Have a nice day.