dragon0023 2019-07-06 04:01
浏览 55

PHP文件如何通过此回调参数了解和处理函数?

I am finding way to get data JSON from PHP file without knowing the function PHP file is processing.

<script>
function clickButton(){
    var s = document.createElement("script");
    s.src = "jsonp_demo_db.php?callback=myDisplayFunction";
    document.body.appendChild(s);
}
</script>
  • 写回答

1条回答 默认 最新

  • dtcd27183 2019-07-06 08:45
    关注

    send the function name with get request and check if is Get value exist and use call_user_func($functionName) and if there is parameter with function you can use call_user_func_array($functionName , $pramaters)

    `function test()
    {
      echo "string";
    }
    
    if ($_GET['func']) {
      $func = $_GET['func'];
      call_user_func($func);
    }`
    

    you can also use function_exists to enshure if the function exist and this function return False or True this code Example :

    if(function_exists('my_function'))
    {
    throw new Exception("'my_function' is already defined!");
    }
    
    function my_function()
    {
      // Do the work here
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集