Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I creat a php variable in javascript, I use this method:

var jArray =  <?php echo json_encode($myArray); ?>;

It's very good but if i view the source code, ther is my full array in the script area.

My problem is that, my php array contains secret data, and I want to use this data in javascritp.

How can I hide from my sourc code, or what can I do?

I tride javascript obfuscation but it can't work with <?php ?> tag.

Thanks!

share|improve this question
5  
You can't hide anything with javascript, if you really want to try to hide it from your viewsource, do some ajax calls. But still it will never be secret. –  Jorge Faianca Jun 18 at 16:52
    
To whom should this data be secret? –  Halcyon Jun 18 at 16:55
2  
As above, nothing client side is secret. Any processing involving sensitive data should be done server side, with only the non sensative result returned to the client –  user574632 Jun 18 at 16:55
    
Dupe of: stackoverflow.com/questions/23740164/… –  Marc B Jun 18 at 16:57
    
You could use AJAX to pass data from JavaScript to a PHP Skript –  Julian Jun 18 at 16:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.