dongyong6045 2013-07-10 22:29
浏览 44
已采纳

如何在运行时动态执行PHP命令?

I wonder is there any way that let's to dynamically load a piece of code at run time? For instance we have a simple "switch...case" statement like this:

switch($choice) {
   case 'help':
      load_from_db('help');
      break;
   case 'about':
      load_from_db('about');
      break;
}

And we have this database:

| keyword | command                          |
   help     require('help.php');
   about    echo 'Under construction.';

"load_from_db" is a function which is capable of reading from DB (we know how to do this) and execute corresponding command stored in the database (my question is this part).

Another example would be a simple "textarea" form which user can write some PHP code within and submit the form. At the server side code will be executed and result wil be shown to the user (I know this is not safe, this is just an example).

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongzhu0327 2013-07-10 22:35
    关注

    You can use, but should always avoid, http://de.php.net/eval

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部