bob_the _builder Posted March 5, 2007 Share Posted March 5, 2007 Hi, Is the following code pluasable to use and safe? foreach($_POST as $key=>$value){ $$key = ValidateInput($value); } Basically then u can use the variable $name rather than $_POST['name'] ? Thanks Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/ Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 why would it matter to use $_POST['name']? what are you trying to accomplish? in the mean time, look into the define() function. i believe you'd be able to store your new variable names into an array... then zip through the names array and the $_POST array to affilliate a certain post variable with a new defined name. Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/#findComment-200388 Share on other sites More sharing options...
bob_the _builder Posted March 6, 2007 Author Share Posted March 6, 2007 Because its tidyer code and less to type. Saves you converting $_POST['name'] to $name = $_POST['name'] So when you use INSERT etc post data goes straight in as $name less code and much tidyer. Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/#findComment-200435 Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 there's no need to convert your post variables. you can use $_POST inside a sql query. if you're worried about sql injection, just write a function and clean all the $_POSTed variables. you can still keep them the same. Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/#findComment-200518 Share on other sites More sharing options...
bob_the _builder Posted March 6, 2007 Author Share Posted March 6, 2007 Hi, Maybe im not explaing my question well enough.. I am covered for sql injection ValidateInput($value); The following code: foreach($_POST as $key=>$value){ $_POST[$key] = ValidateInput($value); } cleans my post data then I use the variable as $_POST['name'] this code: foreach($_POST as $key=>$value){ $$key = ValidateInput($value); } *note: $$key cleans my post data then I can simply use the variable $name This creates less typing and also shorter code. Is this acceptable/safe way to code? Thanks Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/#findComment-200529 Share on other sites More sharing options...
boo_lolly Posted March 6, 2007 Share Posted March 6, 2007 shorter code would be: array_walk($_POST, 'ValidateInput'); Link to comment https://forums.phpfreaks.com/topic/41354-post-data-globals/#findComment-200811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.