📜 ⬆️ ⬇️

Another way to protect against spam emails displayed on the site

The problem of protection from spam emails posted on the site, already painful and long erased to holes. But I accidentally found another way to fight.

You can, of course, use the following methods of protection:
- Graphic image
- Replacing characters. Type spam [at] must [dot] die
- Output via js view
var login = 'spammer' ;
var server = 'must.die' ;
var email = login+ '@' +server;
var url = 'mailto:' +email;
document .write( '<a href="' +url+ '">' +email+ ' '
);


- you can use a simple output & # ANSI_code_symbol; in php:
 $email = 'spammer@must.die'; $url = 'mailto:spammer@must.die'; $safe_email=$safe_url=''; for($i=0; $i<strlen($email); $i++){ $safe_email .= '&#'.ord($email{$i}).';'; } for($i=0; $i<strlen($url); $i++){ $safe_url .= '&#'.ord($url{$i}).';'; } print "<a href='$safe_url'>$safe_email</a>"; 


When for my last project print-com.biz I had to make the protection of the laid out soap from spam, I came across this interesting service in search of it.
Fumbling in the code, we get:
function encode(email, text, tpl) {
var t = tpl.replace(/{e}/g, email);
var a = t.replace(/{text}/g, text);
t = "" ;
for (i = 0; i < a.length; i++) {
if (a.charCodeAt(i) <= 127) {
t += (String.fromCharCode(Math.floor(a.charCodeAt(i) / 16) + 65))
t += (String.fromCharCode(a.charCodeAt(i) % 16 + 65));
} else {
t += a.charAt(i);
}
}
var to = t;

return t;
}
function decode(a) {
var t = "" ;
for (i = 0; i < a.length; i++) {
t += (a.charCodeAt(i) <= 127) ?
String.fromCharCode((a.charCodeAt(i) - 65 ) * 16 + (a.charCodeAt(++i) - 65))
:
a.charAt(i);
}
return t;
}

* This source code was highlighted with Source Code Highlighter .


A natural question arises, why not implement something like this, say, in php?
And that's what happened.
 
  function encode_email ($ email, $ text = null, $ tpl = null) 
  { 
  if (empty ($ email)) return false; 
  if ($ tpl === null) $ tpl = "<A HREF=\"mailto:{e}\" {text} </A>"; 
  if ($ text === null) $ text = $ email; 
  $ t = str_replace ('{e}', $ email, $ tpl); 
  $ a = str_replace ('{text}', $ text, $ t); 
  $ result = ''; 
  for ($ i = 0; $ i <strlen ($ a); $ i ++) { 
  if (ord ($ a [$ i]) <= 127) { 
  $ result. = chr (floor (ord ($ a [$ i]) / 16) + 65) 
  .  (string) chr (ord ($ a [$ i])% 16 + 65); 
  } else { 
  $ result. = (string) $ a [$ i]; 
  } 
  } 
  $ code = ""; 
  $ code. = "<script type = \" text / javascript \ ">" 
  .  "a = \" ". $ result." \ ";" 
  .  "for (i = 0; i <a.length; i ++) {document.write ((a.charCodeAt (i) <= 127)? String.fromCharCode ((a.charCodeAt (i) -65) * 16 + ( a.charCodeAt (++ i) -65)): a.charAt (i))} " 
  .  "</".  "script>" 
  .  "<noscript>". str_replace (array ('@', '.'), array ('©', '·'), $ email). "</ noscript>"; 

  return $ code; 
  } 
 

')


In total for spam [at] must.die soap it turns out, something like:
DMEBCAEIFCEFEGDNCCGNGBGJGMHEGPDKHDHAGBGNEAGNHFHDHECOGEGJGFCCDOWrite a CA letter without SCAM DMCPEBDO.
And after decoding with js, we see a normal email link.

So kick, just not very painful. I would be grateful for any criticism of the case.

Source: https://habr.com/ru/post/43209/


All Articles