{"id":359,"date":"2013-10-16T11:07:25","date_gmt":"2013-10-16T16:07:25","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=359"},"modified":"2014-12-01T15:59:20","modified_gmt":"2014-12-01T21:59:20","slug":"php-and-js-email-obfuscator","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2013\/10\/php-and-js-email-obfuscator\/","title":{"rendered":"PHP and JS Email Obfuscator"},"content":{"rendered":"<p>I have been using some great email obfuscation code created by <a href=\"http:\/\/www.celticproductions.net\/\">Ross Killen<\/a> ,<a href=\"http:\/\/www.u.arizona.edu\/~trw\/spam\/spam4.htm\">Tim Williams<\/a> and <a href=\"http:\/\/www.jottings.com\/obfuscator\/\">Andrew Moulden<\/a>. And like Andrew&#8217;s generator that allows for &#8220;link text&#8221;, I needed a PHP solution for sites I&#8217;m developing. So here&#8217;s my twist:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction munge($address,$link_text) {\r\n\t$address = strtolower($address);\r\n\t$coded = &quot;&quot;;\r\n\t$unmixedkey = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.@-_&quot;;\r\n\t$inprogresskey = $unmixedkey;\r\n\t$mixedkey=&quot;&quot;;\r\n\t$unshuffled = strlen($unmixedkey);\r\n\tfor ($i = 1; $i &lt;= strlen($unmixedkey); $i++) {\r\n        \/\/ set i = 1 because i = 0 was throwing an offset error in PHP \r\n\t\t$ranpos = rand(0,$unshuffled-1);\r\n\t\t$nextchar = $inprogresskey{$ranpos};\r\n\t\t$mixedkey .= $nextchar;\r\n\t\t$before = substr($inprogresskey,0,$ranpos);\r\n\t\t$after = substr($inprogresskey,$ranpos+1,$unshuffled-($ranpos+1));\r\n\t\t$inprogresskey = $before.''.$after;\r\n\t\t$unshuffled -= 1;\r\n\t}\r\n\t$cipher = $mixedkey;\r\n\t$shift = strlen($address);\r\n\t$txt = &quot;&lt;script type=\\&quot;text\/javascript\\&quot; language=\\&quot;javascript\\&quot;&gt;\\n&quot; .\r\n           &quot;&lt;!-&quot;.&quot;-\\n&quot; .\r\n           &quot;\/\/ Email obfuscator script 2.1 by Tim Williams, University of Arizona\\n&quot;.\r\n\t\t   &quot;\/\/ Random encryption key feature by Andrew Moulden, Site Engineering Ltd\\n&quot;.\r\n\t\t   &quot;\/\/ PHP version coded by Ross Killen, Celtic Productions Ltd\\n&quot;.\r\n\t\t   &quot;\/\/ This code is freeware provided these six comment lines remain intact\\n&quot;.\r\n\t\t   &quot;\/\/ A wizard to generate this code is at http:\/\/www.jottings.com\/obfuscator\/\\n&quot;.\r\n\t\t   &quot;\/\/ The PHP code may be obtained from http:\/\/www.celticproductions.net\/\\n\\n&quot;;\r\n\t\t   \r\n\tfor ($j=0; $j&lt;strlen($address); $j++) {\r\n\t\tif (strpos($cipher,$address{$j}) == -1 ) {\r\n\t\t\t$chr = $address{$j};\r\n\t\t\t$coded .= $address{$j};\r\n\t\t} else {\r\n\t\t\t$chr = (strpos($cipher,$address{$j}) + $shift) %\r\n\t\t\tstrlen($cipher);\r\n\t\t\t$coded .= $cipher{$chr};\r\n\t\t}\r\n\t}\r\n\t\r\n\tif($link_text):\r\n\t\r\n\t\t$link_text_block = &quot;document.write(\\&quot;&lt;a href='mailto:\\&quot;+link+\\&quot;'&gt;&quot; . $link_text . &quot;&lt;\/a&gt;\\&quot;)\\n&quot;;\r\n\t\t\r\n\telse:\r\n\t\t\r\n\t\t$link_text_block = &quot;document.write(\\&quot;&lt;a href='mailto:\\&quot;+link+\\&quot;'&gt;\\&quot;+link+\\&quot;&lt;\/a&gt;\\&quot;)\\n&quot;;\r\n\t\t\r\n\tendif;\r\n\t\t\r\n\t$txt .= &quot;\\ncoded = \\&quot;&quot; . $coded . &quot;\\&quot;\\n&quot; .\r\n\t\t\t&quot;  key = \\&quot;&quot;.$cipher.&quot;\\&quot;\\n&quot;.\r\n\t\t\t&quot;  shift=coded.length\\n&quot;.\r\n\t\t\t&quot;  link=\\&quot;\\&quot;\\n&quot;.\r\n\t\t\t&quot;  for (i=0; i&lt;coded.length; i++) {\\n&quot; .\r\n\t\t\t&quot;    if (key.indexOf(coded.charAt(i))==-1) {\\n&quot; .\r\n\t\t\t&quot;      ltr = coded.charAt(i)\\n&quot; .\r\n\t\t\t&quot;      link += (ltr)\\n&quot; .\r\n\t\t\t&quot;    }\\n&quot; .\r\n\t\t\t&quot;    else {     \\n&quot;.\r\n\t\t\t&quot;      ltr = (key.indexOf(coded.charAt(i))-shift+key.length) % key.length\\n&quot;.\r\n\t\t\t&quot;      link += (key.charAt(ltr))\\n&quot;.\r\n\t\t\t&quot;    }\\n&quot;.\r\n\t\t\t&quot;  }\\n&quot;.\r\n\t\t\t\/\/ Original link markup\r\n\t\t\t\/\/&quot;document.write(\\&quot;&lt;a href='mailto:\\&quot;+link+\\&quot;'&gt;\\&quot;+link+\\&quot;&lt;\/a&gt;\\&quot;)\\n&quot; .\r\n\t\t\t\/\/ Link markup from above\r\n                        $link_text_block .\r\n\t\t\t&quot;\\n&quot;.\r\n\t\t\t&quot;\/\/-&quot;.&quot;-&gt;\\n&quot; .\r\n\t\t\t&quot;&lt;&quot; . &quot;\/script&gt;&lt;noscript&gt;Please turn on javascript to email me.&quot; .\r\n\t\t\t&quot;&lt;&quot;.&quot;\/noscript&gt;&quot;;\r\n\t\r\n\treturn $txt;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I have been using some great email obfuscation code created by Ross Killen ,Tim Williams and Andrew Moulden. And like Andrew&#8217;s generator that allows for &#8220;link text&#8221;, I needed a PHP solution for sites I&#8217;m developing. So here&#8217;s my twist: function munge($address,$link_text) { $address = strtolower($address); $coded = &quot;&quot;; $unmixedkey = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.@-_&quot;; $inprogresskey = $unmixedkey; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3,39],"tags":[],"class_list":["post-359","post","type-post","status-publish","format-standard","hentry","category-coding","category-discoveries","category-email"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=359"}],"version-history":[{"count":10,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/359\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}