Call PHP function from url?

前端 未结 14 1630
清歌不尽
清歌不尽 2020-12-04 15:50

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

14条回答
  •  执念已碎
    2020-12-04 16:18

    What your script does is entirely up to you. URLs cannot magically cause Apache, PHP, or any other server component to take a certain behavior, but if you write your program such that a particular function can be executed, it's certainly possible. Perhaps something like:

    switch($_GET['function']) {
    case 'specificFunction':
        specificFunction();
    }
    

    Then you could visit myScript.php?function=specificFunction

    Be extremely careful here to specifically list each allowable function. You must not just take the $_GET['function'] parameter and blindly execute whatever function it says, since that could present an enormous security risk.

提交回复
热议问题