Call PHP function from url?

前端 未结 14 1634
清歌不尽
清歌不尽 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:30

    You could do something like this (not recommended for security reasons): www.exampe.com/myscript.php?run=getNames

    then:

    You would be better off using a php class instead of trying to call a function on the global namespace because they could call a potenitally dangerous function or call a function you don't want them to see the result to:

    $_GET['run']();
    } else {
      echo 'Function not found';
    }
    

    This also wouldn't allow the class's private functions to be called, etc.

提交回复
热议问题