blurredvision Posted August 9, 2008 Share Posted August 9, 2008 I have quite a large form that returns a few dozen values through the POST array. The only way I've ever tried to prevent injection attacks is applying the real_escape_string function to individual variables. Can I simply do this to the entire POST array, then use associative values to input into the database? Link to comment https://forums.phpfreaks.com/topic/118958-can-you-apply-mysqli_real_escape_string-to-the-entire-post-array/ Share on other sites More sharing options...
genericnumber1 Posted August 9, 2008 Share Posted August 9, 2008 Yes... but try to remember that it does apply to the WHOLE post array, even ones you may not want it to apply to. <?php foreach($_POST as $var => $val) { $_POST[$var] = mysqli_real_escape_string($connection, $val); } ?> Link to comment https://forums.phpfreaks.com/topic/118958-can-you-apply-mysqli_real_escape_string-to-the-entire-post-array/#findComment-612553 Share on other sites More sharing options...
cooldude832 Posted August 9, 2008 Share Posted August 9, 2008 If u made a class to handle processing forms you could have <?php class process_form{ public function get_inputs(){ foreach($_POST as $key=>$value){ $this->inputs[$key] = $value; } public function clean_inputs(){ foreach($this->$inputs as $key=>$value){ $inputs[$key] = mysql_real_escape_string($value); } } ?> Link to comment https://forums.phpfreaks.com/topic/118958-can-you-apply-mysqli_real_escape_string-to-the-entire-post-array/#findComment-612554 Share on other sites More sharing options...
cooldude832 Posted August 9, 2008 Share Posted August 9, 2008 Yes... but try to remember that it does apply to the WHOLE post array, even ones you may not want it to apply to. This is a good reason not to provide blanket alterations to super global arrays ($_GET $_POST $_FILES $_SESSION etc.) because you never know in the future if you don't want to touch one. Link to comment https://forums.phpfreaks.com/topic/118958-can-you-apply-mysqli_real_escape_string-to-the-entire-post-array/#findComment-612587 Share on other sites More sharing options...
genericnumber1 Posted August 9, 2008 Share Posted August 9, 2008 Exactly, cooldude I would never implement it how I posted, and I wouldn't think the op would for more than the single form he speaks of. He asked if it could be done, and I told him it could Link to comment https://forums.phpfreaks.com/topic/118958-can-you-apply-mysqli_real_escape_string-to-the-entire-post-array/#findComment-612591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.