Home > OS >  Javascript How to hide a function from my web app (by using php?)
Javascript How to hide a function from my web app (by using php?)

Time:03-06

I am making an web app that has typical javascript structure below. I must hide at least a function or some formulas from the public code because someone can save the page on his computer without paying for the web app membership. I am not sure how to do that. I read a way is to send an array/variable to a php file and solve it there and then return the values to the main page preferably to javascript but to html is also fine. Another way is with cookie. I am new to this and not sure how to do any of these.

"edit" just because some people missunderstood what I am asking I want to clarify that I am asking a way to communicate with php (or something else on a server) do some mathematical operations there that are hidden and return the values.

        function myOpt() {
            var x     = [];
            var y     = []; 
            var a     = [];
            var b     = [];
            var w     = [];
            var h     = [];
             // Do stuff here that should be hidden  
             // Do stuff here that should be hidden  
                drawCurveTypes()
        }

        function drawCurveTypes() {
              var x     = [];
              var y     = []; 
              var a     = [];
              var b     = [];
              var w     = [];
              var h     = [];
                 // Do stuff here that should be hidden  
                 // Do stuff here that should be hidden  
         }
          <script src="https://www.gstatic.com/charts/loader.js"></script>

CodePudding user response:

Use JSON.stringify() on your array and use AJAX to send it to your php script.

On php side, you can json_decode() that same array and work with it.

You could protect that PHP script with sessions, and return an error if one is not allowed to access it.

CodePudding user response:

You can't stop someone to download your client side script code.

Check this How do I hide javascript code in a webpage?

And i can check every client side code with the browser developer tools.

Edit: You mean this:

How do I pass JavaScript to PHP?

Sending a JavaScript array to PHP via POST

Pass Javascript Array -> PHP

This are your HTTP request methods(check for browser compatibility):

HTTP request methods

Every operation on the server-side is hidden(on a normal way without bugs or something else) and the result you send to the client is public.

  • Related