what is a good method to sanitize the whole $_POST array in php?

pjmiller435

New Member
I have a form with a lot of variables which is then sending an email, rather than sanitizing each \[code\]$_POST\[/code\] value with \[code\]filter_var($_POST['var'], FILTER_SANITIZE_STRING);\[/code\] I was after a more simple piece of code. I came up with the below, which seems to work as I believe the default action is \[code\]FILTER_SANITIZE_STRING\[/code\], but I was just wondering what peoples opinions are, and if this is not good practice, perhaps you could tell me why? The \[code\]$_POST\[/code\] values are then individually embedded into new variables, so I would only be using array_map just at the start to sanitize everything...\[code\]$_POST = array_map('filter_var', $_POST);\[/code\]Thank you for your replies, to give you a little more information, basically: I have 20-30 input fields in a form which are being captured, the data is then displayed to the user to check their input, variables are then sanitized, the user is then sent an email and then finally the details are entered into a db. currently I am sanitizing using the above array_map function, as well as FILTER_SANITIZE_EMAIL on the email address before sending an email and then escaping the input using mysql_real_escape_string() before the insert into the db. Without getting into prepared statements etc.. do you think I should be doing anything additionally? thanks again!
 
Back
Top