views:

121

answers:

4

I'm searching for a javascript obfuscator. Though I've found many obfuscators, no one so far seems to be able to handle (ie ignore) inline php code. Example of what I mean by inline php code:

var my_javascript_variable = <?php echo $my_php_variable; ?>;

Is this possible to obuscate, and if so, does anyone know of such a tool?

+1  A: 

Not aware of any obfuscator capable of doing this, but you could simply make your JavaScript code reference a Config Object instead of the PHP code. Then you can obfuscate the main JavaScript code, e.g.

// Config object with anything that has to be assigned through PHP
var Config = { 'foo': '<?php echo $foo?>'  }

// and some obfuscated code that uses the Config object
var _0x76dc=["\x66\x6F\x6F"];alert(Config[_0x76dc[0]]);
Gordon
That's a neat suggestion. Seems to work too. It's the best solution yet, so I will go with it!
Biggles
+2  A: 

I'd suggest not actually obfuscating in the first place but to minify (using yui compressor / jsmin or similar) instead but thats just my opinion

seengee
<nods> Obfuscating for security doesn't work, especially with JS. Compression does make sense.
Pete
A: 

Check out SD JavaScript Obufuscator. It is designed to handle Javascript standalone or embedded in various HTML-like languages (HTML, XML, ASP, PHP).

Ira Baxter
A: 

What about to separate dynamic parts of your javascript with static parts and then obfuscate and/or minimize only static part and leave dynamic part unobfuscated?

uthark