XmisterIS
01-10-2012, 03:03 PM
It's the bane of the web developer's life, trying to hide phone numbers and email addresses from low-lifes who write robots to harvest contact information for spamming purposes.
So I came up with the following function which hides email, phone, etc, inside a bit of javascript, as follows:
function hideIt($string)
{
$chars = str_split($string);
$data = "";
foreach ($chars as $char)
$data .= '\\x'.sprintf("%02X", ord($char));
$javascript = "<script><!-- document.write(\"$data\"); --></script>";
}
And so for example,
hideIt("me@mydomain.com");
returns
<script><!-- document.write("\x6D\x65\x40\x6D\x79\x64\x6F\x6D\x61\x69\x6E\x2E\x63\x6F\x6D"); --></script>
Would that be enough to deter robots? Or do you suppose that the lowlife scum spammers would actually go out of their way to write code to try to read that? (which, admittedly, is not hard to do!)
The other alternative is to use an image, but that is a pain in the arse and not easily modifyable.
So I came up with the following function which hides email, phone, etc, inside a bit of javascript, as follows:
function hideIt($string)
{
$chars = str_split($string);
$data = "";
foreach ($chars as $char)
$data .= '\\x'.sprintf("%02X", ord($char));
$javascript = "<script><!-- document.write(\"$data\"); --></script>";
}
And so for example,
hideIt("me@mydomain.com");
returns
<script><!-- document.write("\x6D\x65\x40\x6D\x79\x64\x6F\x6D\x61\x69\x6E\x2E\x63\x6F\x6D"); --></script>
Would that be enough to deter robots? Or do you suppose that the lowlife scum spammers would actually go out of their way to write code to try to read that? (which, admittedly, is not hard to do!)
The other alternative is to use an image, but that is a pain in the arse and not easily modifyable.