How can I validate user input in simple way?
I have the below function to validate the user input. Can you suggest whether it is OK or not? I just need simple way of validating user input. no need complex way.
function cleanData($data) {
$data = trim($data);
$data = htmlentitie开发者_运维问答s($data);
$data = mysql_real_escape_string($data);
return $data;
}
That's not a validation function. Your cleanData()
function just escapes content. And it mixes HTML escaping with SQL escaping, where you should be applying each individually on a per use basis.
That approach is unprofessional, but in fact functional. (We've seen worse here). You do cover the common issues by using it. If you do in fact apply it to every incoming variable.
精彩评论