duanke2503
duanke2503
2018-06-18 21:39
浏览 64
已采纳

调用函数并通过url PHP传递参数

This is my PHP script:

<?php

function myFunc($param1)
{
echo $param1;
}

if(isset($_GET['action'])){
    if(function_exists($_GET['action'])) {    
        $_GET['action']();
    }
}

?>

Now I want call this function from other php and pass parameter:

http://localhost/data.php?action=myFunc

How to pass parameter to myFunc through url?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douba2011
    douba2011 2018-06-18 21:44
    已采纳

    It is most certainly wrong and insecure (imagine what would happen if you tried calling it with action=unlink&param=somefile.php), but you could do something like:

    With URL: http://localhost/data.php?action=myFunc&param=123

    <?php
    
    function myFunc($param1)
    {
    echo $param1;
    }
    
    if(isset($_GET['action'])){
        if(function_exists($_GET['action'])) {    
            $_GET['action']($_GET['param']);
        }
    }
    
    点赞 评论

相关推荐