How to add php file for calculations

I would like to ask how to add a php file that has to do the calculations but I want the file to be used only by the server, because I am afraid that if every user calculates the given thing the results would be different because of the use of math.random. Is this possible?

Welcome.

I am really confused as to what you are trying to do.

math.random is a JavaScript function, not a PHP one.

And to create a PHP file, just upload a file with the .php extension to the server, and open it in your browser to run it.

5 Likes

Yes the math.random function is in JS but it is embedded in php. But I want to ask if it is not possible to embed the file so that only the server can use and see it and not the user.Since it is a random calculation I am afraid that the results will be different for both users. Is this possible?

It’s code, pretty much anything is possible!

Just note that in the browser, you will need to write code in the Javascript programming language, but on the server, you’ll have to write in the PHP programming language. You can do the same calculations, but you’ll need to recreate the code to make it work in a different language.

If you want to use randomness and get identical results, you could run the calculation once and store the output somewhere (in a file or database) and retrieve and show the results from the previous runs on subsequent requests. So to answer your question: yes, it’s possible.

But I am also confused as to why you want randomness and consistency, so maybe there is a smarter or simpler way to do it.

6 Likes

in asp it would be known as application variable.
There none i found that on php.

Add php if You wanna create variable as service for customer. you will save the result in file or db file. But, as service result You may copy for many people in several regional that would be made different results on different customers.

The keyword is You can’t do that. No function in php. But, you can make it in custom or service.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.