Chapter 15. Data Sanitization

Table of Contents

15.1. Using Sanitize in Your Application
15.2. Making Data Safe for use in SQL and HTML

15.1. Using Sanitize in Your Application

Cake comes with Sanitize, a class you can use to rid user-submitted data of malicious attacks and other unwanted data. Sanitize is a core library, so it can be used anywhere inside of your code, but is probably best used in controllers or models.

// First, include the core library:

uses('sanitize');

// Next, create a new Sanitize object:

$mrClean = new Sanitize();

// From here, you can use Sanitize to clean your data
// (These methods explained in the next section)