Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call PHP function from url?

Tags:

php

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!

like image 484
Gabriel Avatar asked Dec 05 '10 17:12

Gabriel


People also ask

Can JavaScript call a PHP function?

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.

How to run PHP code from JavaScript?

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.


Video Answer


1 Answers

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.

like image 126
Andreas Wong Avatar answered Oct 05 '22 04:10

Andreas Wong