18.3.1. ProblemYou need to be sure that all input is filtered before being used. 18.3.2. SolutionInitialize an empty array in which to store filtered data. After you've proven that something is valid, store it in this array: <?php /* Initialize an array for filtered data. */ $clean = array(); /* Allow alphabetic names. */ if (ctype_alpha($_POST['name'])) { $clean['name'] = $_POST['name']; } else { /* Error */ } ?> 18.3.3. DiscussionBy using a strict naming convention, you can more easily keep up with what input has been filtered. Always initializing $clean to an empty array ensures that data cannot be injected into the array; you must explicitly add it. Once you adopt a technique such as the use of $clean, it is important that you only use data from this array in your business logic. 18.3.4. See AlsoRecipes Recipe 9.2 to 9.9 discuss form input validation for different types of data in detail. |