October 14th, 2009

Even about protection e-mail addresses on webs – pages

About protection e-mail addresses from scanning by spams – robots in the Internet it was written much. More likely on the contrary, it is a lot of. However all the ways long are reduced basically to one – coding of addresses so that spams – robots could not distinguish it{him}, and for the person it is possible. More often to me there were such variants: name [at] server.ru, name (a) server.ru and even name (Shift+2) server.ru. A variant, certainly, too good, but spams – robots quickly “study”. About protection e-mail addresses from scanning by spams – robots in the Internet it was written much. More likely on the contrary, it is a lot of. However all the ways long are reduced basically to one – coding of addresses so that spams – robots could not distinguish it{him}, and for the person it is possible. More often to me there were such variants: name [at] server.ru, name (a) server.ru and even name (Shift+2) server.ru. A variant, certainly, too good, but spams – robots quickly “study”. The skilled Internet serfer will guess, that [at] it is necessary to replace on, but some people copy name [at server.ru address directly in a mailer, and then are surprised - why letters do not reach:) In the beginning the problem of a spam not so disturbed me while once mountains of advertising letters did not fall down on my box. The same day has found a simple output{exit}: "sobachku" it is possible to show as a picture, all rest - as symbols. Externally - usual e-mail and to copy will fail.

I bring to your attention a simple and accessible way of the publication e-mail addresses without fear, that it{he} will be scanned with the spam - robot. Though, probably, also will scan, but for this purpose he should possess an artificial intellect:) Requirements: presence PHP with library GD. Many likely have guessed, that we shall do{make} with addresses. We … shall draw them! We shall name our script email.php. The algorithm is simple enough:

1. One of ways the script receives on an input{entrance} ?-mail the address:

1. We shall receive the address of the author from a database, having specified for example id clauses{articles} or recordings in the guest book (the catalogue of files, links, etc.).

2. We shall pass the address to a script in an obvious kind: email. php? adr=name@server.ru (but it is fraught with that, that e-mail all "is lighted"). Such protection is equivalent her{it} otsutsviju.

3. We shall pass the address to a script in an implicit kind: email. php? name=name*server=server. ru

4. We shall pass the address to a script in the ciphered kind: email.php? adr=anzr@freire.eh (having used function str_rot13 () which displaces codes of all latin letters upwards on 13).

2. The script deciphers the data, generates a picture with the image of the address and returns to its{her} browser.

For the beginning we shall consider process of "drawing" as he subsequently remain constant:

$size = 2;

$im = imagecreate (imagefontwidth ($size) *strlen ($adr), imagefontheight ($size));

Here there is nothing especial. The initial data: $adr - the address which should "be drawn", $size - the size of a font in a picture (it is easily selected on the size and "fat content", is externally similar on Tahoma, Verdana, Arial). Function imagecreate () creates a picture and places the index on it{her} in a variable $im. However for this purpose we shall calculate the sizes of the future picture, proceeding from the size of a font and quantity{amount} of symbols in line.

imagefontwidth ($size) - defines{determines} width of one symbol at the size $size. We shall increase her{it} for length of a line strlen ($adr) and we shall receive width of the future picture. The height of a picture is calculated by function imagefontheight ($size). We add in a palette of the image of color of a background and an inscription (accordingly white and red)

$bg = imagecolorallocate ($im, 255, 255, 255);

$black = imagecolorallocate ($im, 0x00, 0x00, 0x00);

If color of a background of your site not white, we shall make so:

imagecolortransparent ($im, $bg);

Color $bg in a palette becomes transparent, therefore $bg can be any color. Color of symbols is set according to your needs{requirements}.

We do{make} an inscription:

imagestring ($im, $size, 0, 0, $adr, $black);

Also we deduce{remove} a picture:

header (' Content-type: image/png ');

imagepng ($im);

Now we shall consider, in what ways it is possible to receive e-mail for processing. In the table variants of addressing and corresponding fragments of a code are placed.

Extraction e-mail from database MySQL.

email.php? id=1

mysql_connect ("localhost", "username", "password");

mysql_select_db ("database");

$id = abs (intval ($id));

$query = " SELECT email FROM table WHERE table_id = ' $ id ' ";

$result = mysql_query ($query);

$f = mysql_fetch_array ($result);

if (empty ($f [email])) $adr = “n/a”;

else $adr = $f [email];

Direct transfer of the address

email. php? adr=name@server.ru

The additional code is not necessary

Separate transfer of the address

email.php? name=name and

server=server.ru

$adr = $name.. $ server

Transfer of the coded address

email. php? adr=anzr@freire.eh

(the address has been coded by function str_ rot13 (), she will decode it{him}, because letters in the latin alphabet only 26, and displacement each time on 13)

$adr = str_rot13 ($adr);

All script entirely (add the way of reception of the address necessary to you):

<? php

$size = 2;

$im = imagecreate (imagefontwidth ($size) *strlen ($adr), imagefontheight ($size));

$bg = imagecolorallocate ($im, 255, 255, 255);

$black = imagecolorallocate ($im, 0×00, 0×00, 0×00);

imagecolortransparent ($im, $bg);

imagestring ($im, $size, 0, 0, $adr, $black);

header (‘ Content-type: image/png ‘);

imagepng ($im);

?>

The conclusion of a picture instead of real e-mail is done{made} approximately so:

Yours e-mail: <a href = “mailto:name@server.ru”> name@server.ru </a>

Yours e-mail: <img src = ” email.php? adr=name@server.ru “>

Now, when we know how to replace e-mail addresses, it is possible to write function which will make such replacements in the set text by means of regular expressions. It can be demanded at total kill of all conclusion, batch operation of HTML-files, a conclusion of the information from a DB.

Let’s divide{share} the address into 3 parts:

(Name) (Domain). (Zone)

And that already we have a pattern of type:

(. *) (. *). (. *)

Under this formula billions expressions will approach, but we go further under the specification e-mail addresses. The login name should consist from “a-z”, “A-Z”, “0-9″, and also “.”, “_” and “-”. If not I am mistaken, strict rules in this occasion never was, also other symbols somewhere are resolved{allowed}, it is a basis. “A-Z” it is added on a case if the user likes to register the soap “more abruptly”. Length of a name from 2 up to 256-ti symbols (see RFC). Further the domain, too most – “a-z”, “A-Z”, “0-9″, “.”, “-” and all! The length of a domain name the same, unique difficulty – if a soap is not in the domain of the second level, and, say, the third or even the fourth. Here again in RFC to be thrown it is necessary, as also service DNS is not deprived “answer” such as HTTP 414:). The length of the domain cannot exceed 256 symbols, but whether subdomains enter into this number – I do not remember. A zone – here it is simple “a-z”, “A-Z” from 2 up to 4 symbols.

In a result something turns out such:

([a-zA-Z0-9 |. |-| _] {2,256}) (([a-zA-Z0-9 |. |-] {2,256}). ([a-z] {2,4}))

It is possible to check up, whether begin (or come to an end) podvyrazhenija \1, \2 symbols of type “.” Or “-”, is farther – on what the imagination suffices. Using the calculated regular expression (lectures on matanalizu are involuntarily recollected), we shall write function which will replace all e-mail addresses in line with tag IMG and to return the changed line. As function of replacement I used preg_replace () with syntax Perl RegExp.

email_ replace. php

<? php

// Function of replacement e-mail addresses

function email_replace ($text)

{

$exp = ‘ / ([a-zA-Z0-9 |. |-| _] {2,256}) (([a-zA-Z0-9 |. |-] {2,256}). ([a-z] {2,4})) / ‘;

return preg_replace ($exp, ‘ <img src=email.php? name =\1*server =\2 border=0> ‘, $text);

}

// An initial line with set e-mail addresses

$text = <<<END

On all questions write on mine e-mail:

f_mulder@list.ru,

fox58@list.ru,

admin@foxweb.net.ru,

kurepin@sura.ru,

fox58@abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.com

(it is the real address!!!) “;

END;

echo $text; // an initial line

echo “<br>”;

echo email_replace ($text); // the changed line

?>

Comments are closed.

footer

Design & programming by: Web Development Company CONKURENT LLC 2003-2009.