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.

  1. use strip_tags avoid html, css , js tags.
  2. use str_replace("'","\'", $string) prevent sql injection parsing single quote.
  3. 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.

  1. http://ellislab.com/codeigniter/user-guide/libraries/input.html
  2. http://framework.zend.com/manual/2.0/en/modules/zend.filter.html
  3. http://laravel.com/docs/validation

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -