Call PHP function from url?

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

    Try this one

    $urlParams = explode('/', $_SERVER['REQUEST_URI']);
    $functionName = $urlParams[2];
    $functionName($urlParams);
    
    
    function func1 ($urlParams) {
        echo "In func1";
    }
    
    function func2 ($urlParams) {
        echo "In func2";
        echo "
    Argument 1 -> ".$urlParams[3]; echo "
    Argument 2 -> ".$urlParams[4]; }

    and the urls can be as below
    http://domain.com/url.php/func1
    http://domain.com/url.php/func2/arg1/arg2

提交回复
热议问题