Welcome Guest, Not a member yet? Register   Sign In
Safely parsing complex permutations of $_POST data
#1

[eluser]antonumia[/eluser]
hi all,

I have a complex form which posts to ci for processing.

My problem is that there will be various permutations of fields sent for final processing at the moment there are 10-20 initial premutations with up to 10 subpermutations.

Can anyone suggest a safe way of dealing with variable fields in the $_POST data without having to write a endless switch statements dealing with every permutation.

thanks

anton
#2

[eluser]Tominator[/eluser]
Hello,
you can make function like this:

Code:
function MakeMeSave(&$input) {
   if(is_array($input)) {
      array_walk_recursive($input,"SaveValue");
   } else {
      safetyValue($input);
   }
}
function SaveValue(&$value) {
    
   if (get_magic_quotes_gpc()) {
      $value = stripslashes($value);
   }
  
   $value = htmlspecialchars($value);
   $value = str_replace("'", "'", $value);
   $value = str_replace("\\", "\\\\", $value);
   $value = str_replace("%", "%", $value);
   $value = trim($value);
}

And then in your code you can call just:
Code:
MakeMeSave($POST);

It will work correctly in PHP5. If would you like to make max-lenght limit, you can just add line.




Theme © iAndrew 2016 - Forum software by © MyBB