If I want to execute a php script, i just point the browser to www.something.com/myscript.php
But if i want to execute a specific function inside myscript.php
, is there a way? something like www.something.com/myscript.php.specificFunction
Thanks!
The reason you can't simply call a PHP function from JavaScript has to do with the order in which these languages are run. PHP is a server-side language, and JavaScript is primarily a client-side language.
You can run a local PHP server using php -s localhost:8000 command and open localhost:8000/index. html from the browser to see your HTML page. When you click on the button, the fetch() method will be executed and JavaScript will put the response inside the <div> element.
One quick way is to do things like
something.com/myscript.php?f=your_function_name
then in myscript.php
if(function_exists($_GET['f'])) { $_GET['f'](); }
But please, for the love of all kittens, don't abuse this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With