html - php 5.5 text area input filtering & output escaping -
from researching best way sanitize html form data, have found should "filter input" , "escape output."
unfortunately of info on subject out there old information (php 4.x, 2009, etc.). many web pages recommend mysql_real_escape_string deprecated of php 5.5.0.
i on php 5.5.x, apache web server, , mysql database. using pdo prepared statements. character sets utf-8.
i have looked @ php sanitize filters (found here: http://www.php.net/manual/en/filter.filters.sanitize.php).
i have filtered inputs , escaped outputs except textareas. text areas user "describe event." these large @ 500 characters. 1 spot feel vulnerable malicious code.
the first thing input trim() function.
what best filters run on input?
how should escaping output?
i want output readable.
thank in advance.
the answer depends input kind want filter. let's assume want simple plain text in textarea, need avoid javascript, css , html code need prevent sql injection in input , 500 characters of length.
- use strip_tags avoid html, css , js tags.
- use str_replace("'","\'", $string) prevent sql injection parsing single quote.
- use substr cut string in 500 characteres if more limit.
i recommend visit : https://www.owasp.org/index.php/top_10_2013-top_10
also recommend use php framework avoid tradicional way in work common security risks.
in opinion can use zend, code igniter or laravel.
Comments
Post a Comment