BellaBook3.2: Mangle Email Addresses with JavaScript
This tutorial will show you how to stop e-mail address-collecting bots from being able to easily harvest any e-mail addresses found in BellaBook3.2 entries.
Open up index.php in a text editor (such as Notepad) and find the following lines:
$date = strtotime($date);
$date = date($dateformat, $date);
$message = stripslashes($message);
$message = trim($message, ""x00..x1F");
Right beneath those, add the following code:
$emailarr = explode(" ", $email);
Next, find this part:
if ($showemail == "yes" && !empty($email)) {
echo "<a href="mailto:$email" title="email">@</a> · ";
}
Change it to look like this:
if ($showemail == "yes" && !empty($email)) {
?><script type="text/javascript">
<!--//
var showname = "<?php echo $emailarr[0]; ?>";
var showhost = "<?php echo $emailarr[1]; ?>";
document.write("<a href=" + ""mail" + "to:" + showname + "@")
document.write(showhost + "" title="E-mail <?php echo $name; ?>">@</a> · ")
//-->
</script>
<?php }
Open up sign.php. Find this part:
$entryformat = "$name,$email,$url,$signdate,$ip,"$comments"n";
Add this code directly ABOVE that line:
$email = str_replace("@", " ", $email);
The next thing we need to do is to convert all existing entries' e-mail addresses to the new "protected" format. To do this, you'll need to open up entries.txt in a plain text editor with a search and replace function (Notepad for Windows XP is a good example - eariler versions may not have this function) and replace any instances of "@" (no quotes) with " " (a space; again, no quotes).
Try loading index.php in your browser and doing a hard refresh (CTRL + F5). If everything appears to be working correctly (click on a couple of the e-mail links to check that they work properly. Also check what link title is displayed in the status bar (if you have one) when you hover over addresses). If the addresses aren't appearing, or they aren't linking properly, make sure you have correctly followed the steps above.
Now we need to edit the admin panel to show the protected e-mail addresses properly. Open up admin.php (in a text editor this time, not your browser) and look for the following part:
$date = strtotime($date);
$date = date($dateformat, $date);
$message = stripslashes($message);
$message = trim($message, ""x00..x1F");
$sitename = str_replace("http://", "", $url);
$sitename = str_replace("www.", "", $sitename);
Underneath that, add this:
$email = str_replace(" ", "@", $email);
There are two instances of this code. You will need to add the above line to both of them.
Next, find this part:
$entryary = preg_split("/,(?! )/", $content[$entry]);
$entryary['5'] = stripslashes($entryary['5']);
$entryary['5'] = trim($entryary['5'], ""x00..x1F");
Below it, add this line:
$entryary[1] = str_replace(" ", "@", $entryary[1]);
Again, there are two instances of this code, and you will need to edit them both.
The last step is to find this part:
$editedentry = $newname . "," . $newemail . "," . $newurl . "," . $newdate . "," . $ip . "," . ""$newcomments"" . "n";
ABOVE that line, add this:
$newemail = str_replace("@", " ", $newemail);
As above, there is more than one instance of this code and you need to edit them both.
That's it! If anything is not working, read back over the steps to see if you missed anything.
Please note that JavaScript "munging" of e-mail addresses is not guaranteed to stop spamming to displayed addresses. This measure is intended only to slow down e-mail address-harvesting robots and is not likely to stop it completely.
Tags:
bellabook, javascript,
Last Updated On: 05th May 06 by Amelie
Bookmark At: StumbleUpon, Digg

Handy Stuff
Downloads
Friends of 'TT'
Resources