Filtering $_POST data

The process of filtering data can encompass any or all of the following:

  • Removing unwanted characters (that is, removing <script> tags)
  • Performing transformations on the data (that is, converting a quote to &quot;)
  • Encrypting or decrypting the data

Encryption is covered in the last recipe of this chapter. Otherwise, we will present a basic mechanism that can be used to filter $_POST data arriving following form submission.

How to do it...

  1. First of all, you need to have an awareness of the data that will be present in $_POST. Also, perhaps more importantly, you will need to be aware of the restrictions imposed by the database table in which the form data will presumably be stored. As an example, have a look at the database structure ...

Get PHP 7 Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.