views:

364

answers:

4

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%5Fencoder.php but that relies on some of their special software to be loaded on the server - ie, a no-go...

Any suggestions?

+1  A: 

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
A: 

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
+2  A: 

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
+1 .. I think you said first while I was typing
Xinus
What about text in `<pre>` tags ?
Pierre Bourdon
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
@delroth: No support whatsoever for <pre> 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 <pre> elements used nowadays, outside of sites that allow posting code, like SO? Also, nice name. :P
Duroth
If you want to reduce the size even more, check if the browser supports on-the-fly compression and compress the data.
some
also its been deprecated http://www.w3schools.com/TAGS/tag_pre.asp
Xinus
@Xinus: I can only see that the width-attribute of the pre-tag has been deprecated, not the tag itself.
some
A: 

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

mnml