Hello, i have code what converts html to javascript encoded code: function javascriptencode($text) { $output = ''; for ($i = 0; $i < strlen($text); $i++) $output .= '%' . dechex(ord($text[$i])); $crypto = strtoupper($output); return $crypto; } PHP: and i using it: $txt = " text text text txt " ; header( "Content-type: application/javascript" ) ; echo javascriptencode($txt) ; PHP: The output will be: %A%20%20%20%20%20%20%20%20%74%65%78%74%A%20%20%20%20%20%20%20%20%74%65%78%74%A%20%20%20%20%20%20%20%20%74%65%78%74%A%74%78%74%A%9 Code (markup): Wan it must be: %0A%20%20%20%20%20%20%20%20%74%65%78%74%0A%20%20%20%20%20%20%20%20%74%65%78%74%0A%20%20%20%20%20%20%20%20%74%65%78%74%0A%74%78%74%0A%09 Code (markup): Now how javascript decodes it, first what was generated by php: %A text%A text%A text%Atxt%A%9 Code (markup): And second: text text text txt Code (markup): Problem is here: %A%20%20... %0A%20%20... and %74%A%9 %74%0A%09 How to fix what problem? Thanks.
The problem is that dechex is returning only as many characters as it needs to. It's like 0500 in a decimal number system is the same as 500, because that leading zero doesn't need to be there. Try this: function javascriptencode($text) { $output = ''; for ($i = 0; $i < strlen($text); $i++) { $hexdigit = dechex(ord($text[$i])); if(strlen($hexdigit) < 2) { $hexdigit = "0". $hexdigit; } $output .= '%' . $hexdigit; $crypto = strtoupper($output); } return $crypto; } PHP:
Well actually its php, who works wt javascript. What code will encode javascript code ore html to something that normal people cant read. for example: "lol" will be "%6C%6F%6C". That code will be unescaped by javascript, but if person will view source it will see %6C%6F%6C, but javascript will output "lol" . Thats not good way to hide source, but its good way to show content only if javascript turned on . That next? Convent all your javascript files to php and than output encrypted code. Next? Add domain lock and on self die, so if victim will try to open it directly it will see blank page. Ore if victim will try to link to your javascript file from other web, nothing will be showed.