phpianer Posted July 24, 2006 Share Posted July 24, 2006 HI,I want to call a function with a var like: www......page.php?f=echo$a=$_GET['f'];$a('asadsadasd');is something like this possible in php??Thanks Quote Link to comment https://forums.phpfreaks.com/topic/15523-call-function-with-variable/ Share on other sites More sharing options...
wildteen88 Posted July 24, 2006 Share Posted July 24, 2006 You can with eval:[code]<?phpif(isset($_GET['a'])){ $a = $_GET['a']; eval("{$a}('hey this works');");}?><br /><a href="?a=echo">Test</a>[/code]However be careful with the use of eval. Make sure there is no nasty code stored within the 'a' variable. Quote Link to comment https://forums.phpfreaks.com/topic/15523-call-function-with-variable/#findComment-63046 Share on other sites More sharing options...
ChaosXero Posted July 24, 2006 Share Posted July 24, 2006 [code]<?if(!empty($_GET['echo']) {do_your_function();} else {do_something_else();}?>[code][/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/15523-call-function-with-variable/#findComment-63049 Share on other sites More sharing options...
ryanlwh Posted July 24, 2006 Share Posted July 24, 2006 if you've tried your code out, you should be able to answer yourself with a 'yes'... however, that's very dangerous strategy because i can change the url to some critical function name and screw up your server. so, it's better to use ChaosXero's method so that you have a layer of security over what function to be used. Quote Link to comment https://forums.phpfreaks.com/topic/15523-call-function-with-variable/#findComment-63056 Share on other sites More sharing options...
phpianer Posted July 24, 2006 Author Share Posted July 24, 2006 Yes thinks , i wil cotrole it with an array Quote Link to comment https://forums.phpfreaks.com/topic/15523-call-function-with-variable/#findComment-63083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.