Call PHP function from url?

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

    You will have to expose it in some way. This is because exposing all methods public, would be a security risk.

    Example.php

    <?php
    
        function CalculateLength($source)
        {
            return strlen($source);
        }
    
        if(isset($_GET['calculate-length']) && isset($_GET['value']){
            die(CalculateLength($_GET['value']));
        }
    
    ?>
    

    Then just call:

    http://www.example.com/Example.php?calculate-length&value=My%20example
    
    0 讨论(0)
  • 2020-12-04 16:35
     if (isset($GET[param_name])){
    
      if($GET[param_name] === value)
       {
          function 1... 
        } else if 
     {
    
    function 2...
     }
    
    }
    
    0 讨论(0)
提交回复
热议问题