GD77 Posted August 13, 2012 Share Posted August 13, 2012 Hello: Trying to make variables global inside a function dynamically: foreach($_POST as $ke => $val) { $$ke= trim($_POST[$ke]); global $$ke; } then I call that function inside another one to be used the global... not working how to fix it plz. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/ Share on other sites More sharing options...
Mahngiel Posted August 13, 2012 Share Posted August 13, 2012 why on earth would you want to set a user submitted value as a global? why are you even using globals? Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1368996 Share on other sites More sharing options...
GD77 Posted August 13, 2012 Author Share Posted August 13, 2012 you are right and m not going to use but when I need to set a variables as globals multiple vars what s wrong with my code so it s not doing it? Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1369000 Share on other sites More sharing options...
xyph Posted August 13, 2012 Share Posted August 13, 2012 Well, rather than help you find the solution to your problem, do you mind us trying to show you a better alternative to this? Also, please include more of your code. Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1369014 Share on other sites More sharing options...
GD77 Posted August 13, 2012 Author Share Posted August 13, 2012 yes I m opened to all alternatives and this is the code nothing more: function tst() { foreach.... } Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1369023 Share on other sites More sharing options...
Jessica Posted August 13, 2012 Share Posted August 13, 2012 Your function should return values if you need them outside of the function. Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1369034 Share on other sites More sharing options...
PFMaBiSmAd Posted August 13, 2012 Share Posted August 13, 2012 Arbitrarily setting program variables, named directly from externally submitted data, without any limits/restrictions or validation of the name, would allow a hacker to set any of your program variables to anything he wants. Quote Link to comment https://forums.phpfreaks.com/topic/267021-setting-dynamic-global-vars/#findComment-1369037 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.