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

时间:2018-06-18 21:39:42

标签: php

这是我的PHP脚本:

<?php

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

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

?>

现在我想从其他php调用此函数并传递参数:

  

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

如何通过url将参数传递给myFunc?

1 个答案:

答案 0 :(得分:3)

这肯定是错误的并且不安全(想象如果你尝试用instances调用它会发生什么),但你可以做类似的事情:

使用网址:Content Security Policy: The page's settings blocked the loading of a resource at self ("default-src"). iframe.html:1 Content Security Policy: The page's settings blocked the loading of a resource at self ("default-src"). Source: .vimvixen-console-frame { margin: 0; Received message: !_{"h":"I0_1529357937694"} from https://openmaptiles.firebaseapp.com client.js:181:7 Received message: trunc !_{"s":"/I0_1529357937694::_g_restyleMe","f":"I0_1529357937694","r":"I0_1529357937694","t":"33540592","c":2,"a":[{"setHideOnLeave":false}],"g":false} from https://openmaptiles.firebaseapp.com client.js:181:7 Received message: !_{"s":"__cb","f":"I0_1529357937694","r":"I0_1529357937694","t":"33540592","c":null,"a":[4,[null]],"g":false} from https://openmaptiles.firebaseapp.com client.js:181:7 Received message: !_{"s":"__cb","f":"I0_1529357937694","r":"I0_1529357937694","t":"33540592","c":null,"a":[3,[true]],"g":false} from https://openmaptiles.firebaseapp.com client.js:181:7 Received message: !_{"s":"/I0_1529357937694::authEvent","f":"I0_1529357937694","r":"I0_1529357937694","t":"33540592","c":3,"a":[{"type":"authEvent","authEvent":{"type":"signInViaRedirect","eventId":null,"urlResponse":null,"sessionId":null,"postBody":null,"error":{"code":"auth/network-request-failed","message":"A network error (such as timeout, interrupted connection or unreachable host) has occurred."}}}],"g":false} from https://openmaptiles.firebaseapp.com client.js:181:7

action=unlink&param=somefile.php