Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14625 reviews 1734 hosting providers

Questions & Answers

Filtering user submitted data in PHP

May 14, 2012 by darkshark
Hi all..
I am working on a contact form and I need to filter the user input data(posted variables), and I don’t want to do it  individually. I am looking for a way to filter the posted variables easily in PHP. Can anyone here help me please?
thanks

2 Answers

0 votes
May 14, 2012 by lightSpeed
PHP function to filter the user supplied data.
function filter_data($val)
{
  return htmlentities($val,ENT_QUOTES);
}
This is just a example of very simple function is PHP to filter the user submitted data.But ,you can add more code according to your requirement to make this function robust.
0 votes
May 14, 2012 by expert
You can also use use array_map() function to filter the posted data in PHP
using the callback function. you can filter the the posted data easily with this code
$post=array_map("filter_data",$_POST);
then you can access the filtered variables easilly with $post['name'] or $post['email'] etc.