3

I know, I know - obfuscated html/js code is useless (I read the other questions on SO), but I still want to make life harder for copy-cats of my site...

I'm running a php based website, which generates html output. I would like the FINAL html output (which has html, js, json and uses ajax) to be obfuscated. Is there a php function for that purpose? I found http://www.ioncube.com/html_encoder.php but that relies on some of their special software to be loaded on the server - ie, a no-go...

Any suggestions?

Steve
  • 1,857
  • 5
  • 32
  • 45
  • 15
    I didn't really have any problems viewing their page with firebug, though... :\ – peirix Oct 21 '09 at 11:23
  • I agree this is a silly question. What makes you think you are so special, when loads of really good designers/developers (Zeldman, Shea, Cederholm etc.) don't obfuscate their HTML? –  Oct 21 '09 at 11:32
  • 1
    Like many others has said: Don't bother. If someone wants to look at your code they can do so with the right tool. It is a lost battle. You will spend more time trying to obfuscate than someone who want to look at your code. Also, you pages will not be indexed by search enginges, your pages requires javascript. I took a peek on ioncube and saw that their code is slow (and very slow on IE). It took less than 2 minutes to make it more than twice as fast on all browsers and even faster on IE (didn't bother to profile how much) – some Oct 21 '09 at 13:13
  • Facebook obfuscates its html code. I dont think abfuscation of html is bad idea. – Taleh Ibrahimli Jul 23 '13 at 20:15

5 Answers5

6

Not true obfuscation, but rather hard to read in most cases (and less bandwidth-intensive as well!)

<?php
ob_start();

// Generate output here

$output = ob_get_contents();
ob_end_clean();

$output = preg_replace('\s{2,}',' ', $output);
echo $output;
?>
Duroth
  • 6,315
  • 2
  • 19
  • 23
  • 4
    What about text in `
    ` tags ?
    – Pierre Bourdon Oct 21 '09 at 11:42
  • I only use compressed css and JavaScript not for obfuscation but for reducing size, but for html you can take care of it in callback function.. – Xinus Oct 21 '09 at 11:49
  • @delroth: No support whatsoever for
     tags, I'm afraid. I guess it could be done relatively easily, using either an HTTP parser or a slightly more interesting regexp, but then again, how often are 
     elements used nowadays, outside of sites that allow posting code, like SO? Also, nice name. :P
    – Duroth Oct 21 '09 at 11:52
  • If you want to reduce the size even more, check if the browser supports on-the-fly compression and compress the data. – some Oct 21 '09 at 11:55
  • @Xinus: I can only see that the width-attribute of the pre-tag has been deprecated, not the tag itself. – some Oct 21 '09 at 13:01
3

You can compress your JavaScript and css

For php output it can be done using ob_start have a look at this http://ru.php.net/manual/en/function.ob-start.php#71953

Xinus
  • 29,617
  • 32
  • 119
  • 165
1

You should have a look at Minify it has a Minify_HTML class removing whitespace, unnecessary comments and tokens

Roch
  • 21,741
  • 29
  • 77
  • 120
1

Well, in my studies of HTML obfuscator, like http://htmlobfuscator.com/, are truely change their "special" code into reversed base64. When we decode it, they're actually packed js file using packer that you could find on Google.

So, now we could do this
Slashup the whole html, for the Js string, then "pack" the javascript, then encode it into base64, then rotate the encoded string. Viola, done. You'll get something like this:

var IO1='KkSKpcCfngCdpxGcz5yJr9GfwRHdox3YyNHfmVmc8NmczRXZnxXZtFmTnFGV5J0c05WZtVGbFRXZnxXawFWeyVWdxpGf0BXayN2c8xmc1xXZwF2YzVmb1xnclJnclZWZyxHZslGaDRmblBHchx3bm5Wa8VGdpJ3d8xHduVWblxWRlRXYlJ3Y8VGb0lGdDNDfDJDfs1GdoxXek9mYDNDfyl2cwIDf0NXZ0V0M8x3bsxWZIV0M8VGb0lGd8RWYlh2QzwHbtRHaDNDfMJVV8V0M8FTSPxHduVmbvBXbvNUSSVVZk92YuVGfJ9US8RWYlhGfyFmd8N0M8JjN8JTO8hzM8Rnbl1Wdj9GZ8VGchN2cl9Ff5R2bixHbhZXZ8ZzM8VzM8VGZvNkchh2Qt9mcmxHdpxGczx3Zulmc0N1b0xHc4V0ZlJFf05WSlNnchBHf3Vmb8VGbph2d8ZWa8dmbpJHdTxXZjFGbwVmc85mc1RXZyxnbvlGdj5WdmxHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHf8xHfnwCO0EDLyYDLnkSK9tHLwwSKnwFfnwFKFFjLnwFNywnNyw3NywHOywnYyw3MywnMywHWxw3VxwXWxwn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HXcxFXnwldxsXKoUXM9U2Od1XXltFZgYXM7lSZoUXMb1za9lyYoUGf811YbtWPdlyYoU2WktXKt0yYooXM7lSK4FDLv41LocXMucCXnwVIokXM70XKpgUMoQUMuMmOpkjMrMGKGFjL4FzPHFjPpEWJj1zYogyKpkSKh9yYoIUMoUmOnw1Jc9TY8MGK2FzepMGK1FTPltXKkxSZssGLjxSYsAHK1FDKJFzJo0Hcg4mc1RXZy1Xfp01YbtGLpcyZnwyJixFXnsSKjhSZrciYcx1JoAHeFdWZSBydl5GKlNWYsBXZy5Cc9A3ep01YbtGKml2ep0SLjhSZslGa3tTfpkiNzgyZulmc0N1b05yY6kSOysyYoUGZvNkchh2Qt9mcm5yZulmc0N1P1MjPpEWJj1zYogyKpkSKh9yYoQnbJV2cyFGcoUmOncyPhxzYo4mc1RXZytXKjhibvlGdj5Wdm1TZ7lCZsUGLrxyYsEGLwhibvlGdj5WdmhCbhZXZ';function l1O(data){var OOOlOI="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var o1,o2,o3,h1,h2,h3,h4,bits,i=0,enc='';do{h1=OOOlOI.indexOf(data.charAt(i++));h2=OOOlOI.indexOf(data.charAt(i++));h3=OOOlOI.indexOf(data.charAt(i++));h4=OOOlOI.indexOf(data.charAt(i++));bits=h1>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){enc+=String.fromCharCode(o1)}else if(h4==64){enc+=String.fromCharCode(o1,o2)}else{enc+=String.fromCharCode(o1,o2,o3)}}while(i= 0; i-- ){ ret += string.charAt(i);} return ret; }eval(l1O(OOO(IO1)));

Good luck~

Chris Qiang
  • 223
  • 4
  • 19
0

No, php couldn't do that without something on the client side. You could always have some javascript decode it, but that wouldnt be friendly to whoever has it turned off, it would be slow and no search engine support.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445