sanitizing input with php

Wise Guy
Soldato
Joined
23 May 2009
Posts
5,748
What is the best way to clean form inputs with php, like for forum posts?

Is strip_tags and then mysql_real_escape_string enough? Do you trust the php functions?
 

aln

aln

Associate
Joined
7 Sep 2009
Posts
2,076
Location
West Lothian, Scotland.
It's interesting that the first filter from that list, the email, rejects valid email addresses. It's stuff like that which gets PHP a bad rep. :p

Also using PDO doesn't help prevent SQL injections but using prepared statements, which PDO makes available to you, does. I'm behind PDO usage, for sure, but you can still use it wrong.

Write a validation class / functions, use regex, better yet, use a framework and follow the guidelines.
 
Soldato
Joined
4 Mar 2010
Posts
5,038
It's interesting that the first filter from that list, the email, rejects valid email addresses. It's stuff like that which gets PHP a bad rep. :p

Also using PDO doesn't help prevent SQL injections but using prepared statements, which PDO makes available to you, does. I'm behind PDO usage, for sure, but you can still use it wrong.

Write a validation class / functions, use regex, better yet, use a framework and follow the guidelines.
Ah yes, I should have explicitly said use the prepared statements within PDO! :)

Hahah are you serious about the email filter? I felt that since learning C#, php gives people bad habits and the names of built in functions were terrible, but I didn't realise that they were buggy too!
 
Back
Top Bottom