Configuration

From PhpInputValidator

Jump to: navigation, search

The phpInputValidator has default configuration settings that will be setup when no values override them. So if you do not want to configure the system you don't have to.

Contents

How to configure

To configure phpInputValidator you can do one of two ways. First is to pass an array of configuration values to the constructor when creating a new instance of the class. Here is an example:

$config = array('date_format' => 'D, d M Y H:i', 'language' => 'en_us');
$getvar = phpInputValidator::getInstance($config);

Second is to use a the config method:

$getvar = phpInputValidator::getInstance();
$getvar->config->date_format('D, d M Y H:i');
$getvar->config->language('en_us');

Configuration options

add_slashes (bool)

Add slashes to strings

Example

$config = array('add_slashes' => true);

-- OR --

phpInputValidator::getInstance()->add_slashes(true);

add_slashes_function (string)

A function to run to add slashes to data. By default the php function addslashes is run to add slashes to a string.

However it is generally better to run a DB specific function for adding slashes. A couple of examples of better functions to use might be mysqli_real_escape_string or mysql_real_escape_string. Which you can use by using this configuration option.

Example

$config = array('add_slashes_function' => 'mysqli_real_escape_string');

-- OR --

phpInputValidator::getInstance()->add_slashes_function('mysqli_real_escape_string');

date_format (string)

This is the formatting you wish to apply to the date and time on logged events. The string needs to follow the php date function formatting. An example: 'D, d M Y H:i'

Example

$config = array('date_format' => 'D, d M Y H:i');

-- OR --

phpInputValidator::getInstance()->date_format('D, d M Y H:i');

error_log (string)

This is the name and location you wish to give the error log. If one is not given errors are not logged.

Example

$config = array('error_log' => dirname(dirname(__FILE__)).'/log/error_log.txt');

-- OR --

phpInputValidator::getInstance()->error_log(dirname(dirname(__FILE__)).'/log/error_log.txt');

language (string)

The language file to load.

Example

$config = array('language' => 'en_us');

-- OR --

phpInputValidator::getInstance()->language('en_us');

log_path (string)

This is the name and location you wish to give the log. If one is not given then use is not logged.

Example

$config = array('log_path' => dirname(dirname(__FILE__)).'/log/log.txt');

-- OR --

phpInputValidator::getInstance()->log_path(dirname(dirname(__FILE__)).'/log/log.txt');