Call PHP function from url?

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

    I am using this on my website. To use this simply format your url like this www.something.com/myscript.php?function=myFunction&arg=foo&otherarg=bar It doesn't matter what you call the args in the url and you can have as many args as you want.

    0){
                    //handle args
                    foreach($_GET as $arg){
                       array_push($args,$arg);
                    }
                }
                $result = call_user_func_array($function,$args);
                //this part is only necessary if you want to send a response to a http request.
                if(is_bool($result)){
                    die(($r)?'true':'false');
                }
                else if(is_array($result)){
                    die(json_encode($result));
                }
                else {
                    die($result);
                }
            }
            myFunction($foo,$bar){
                echo $foo." ".$bar;
            }
        ?>
    

提交回复
热议问题