What risks do I have to consider when encrypting server side as opposed to client-side?

How do you indent JavaScript printed by PHP (or another server side language)?

  • For a better idea of what I'm asking consider: A) No JavaScript indentation: echo "_____"; echo "_____"; echo "_____"; B) Within PHP source: echo "_____"; echo "_____"; echo "_____"; C) With spaces (so that resulting identation is visible in HTML source): echo "_____"; echo " _____"; echo " ______";

  • Answer:

    There's rarely a good reason to do either of those options. If you really can't think of a better way to do it (e.g. simply using PHP to generate a JSON configuration object), then I would just embed PHP in the JS: /** * Generated JS */ myApp.foo = function(bar) { var pattern = '<?php echo $foo->getPattern(); ?>'; var id = '<?php echo $foo->getId(); ?>'; return bar.match(pattern); }; or create a JS template: /** * JS Template */ myApp.foo = function(bar) { var pattern = %pattern%; var id = %id%; return bar.match(pattern); };

Calvin Huang at Quora Visit the source

Was this solution helpful to you?

Other answers

if it's a single block of js then i would just use the fact that you can spread a single php string over several lines. this will give you your desired js formatting. for example: printf(" myApp.foo = function(bar) { var pattern = '%s'; var id = '%s'; return bar.match(pattern); }; ", $foo->getPattern, $foo->getId() );

Bhu Boue Vidya

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.