I was wondering if converting POST input from an HTML form into html entities, (via the PHP function htmlentities() or using the FILTER_SANITIZE_SPECIAL_CHARS constant in tandem with the filter_input() PHP function ), will help defend against any attacks where a user attempts to insert any JavaScript code inside the form field or if there’s any other PHP based function or tactic I should employ to create a safe HTML form experience?
Sorry for the loaded run-on sentence question but that’s the best I could word it in a hurry.
Any responses would be greatly appreciated and thanks to all in advance.
racl101
It would turn the following:
into
So if you’re printing out this data into HTML later, you would be protected. It wouldn’t protect you from:
just in case you were echoing into a script like so:
For this purpose, you should use
addslashes()and a database string escaping method likemysql_real_escape_string().