Recommend this page to a friend! |
![]() |
Info | Example | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2025-05-08 (-1 hours ago) ![]() | Not enough user ratings | Total: 398 | All time: 6,592 This week: 38![]() |
Version | License | PHP version | Categories | |||
php-sanitize-class 1.0.10 | GNU General Publi... | 5.2.0 | PHP 5, Libraries, Validation, Security |
Description | Author | ||||||||
This package can be used to validate and sanitize string values. |
|
Best Package to Address SQL Injection Vulnerabilities
Upgrading security of existing MySQL code
<?php |
This package is a set of classes that will help to validate/sanitize the main set of types listed in OWASP, through a PHPSanitizer wrapper class.
It allows to create new validation classes for customs types by extending AbstractSanitizer class and implements ISanitizer interface.
First, get an instance of PHPSanitizer, you can do that through ClassLoader class:
...
require_once(dirname(__FILE__).'/<path_to_classes>/ClassLoader.php');
ClassLoader::Register();
$base_path = dirname(__FILE__).'/<path_to_PHPSanitizer>/';
ClassLoader::Load('PHPSanitizer', $base_path);
$sanitizer = PHPSanitizer::getInstance();
...
or just:
...
require_once(dirname(__FILE__).'/<path_to_classes>/PHPSanitizer.php');
$sanitizer = PHPSanitizer::getInstance();
...
by default it uses "PARANOID" validation, you can change type using setType($type, $custom_name, $base_path)
method,
where $type can be one of:
In case of PHPSanitizer::CUSTOM
, $custom_name is required following naming rules that will be detailed in Extends section.
$base_path is optional. This is used to change default path for Sanitizers classes, defaulted in factories directory
under the path to SanitizerFactory class.
There are two method available in $sanitizer instance: validate($string) and cleanup($string)
sanitizer->validate($string); //return a boolean
$sanitizer->cleanup($string); //returns an string with all invalid characters removed
To create a new CUSTOM sanitizer, you just need to extend AbstractSanitizer class and implements ISanitizer interface.
// This file is under examples/factories/.
require_once(dirname(__FILE__).'/../../factories/AbstractSanitizer.php');
require_once(dirname(__FILE__).'/../../factories/ISanitizer.php');
class SanitizerEmail extends AbstractSanitizer implements ISanitizer{
private $pattern = "/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/";
private $pattern_replace = "/[\;\#\n\r\*\'\"<>&\%\!\(\)\{\}\[\]\?\\/\s,]/";
private $replacement = "";
public function validate($string){
return preg_match($this->pattern, $string);
}
public function cleanup($email){
$email = trim($email);
$email = str_replace(" ", "", $email);
if(count(explode('@',$email))>2){
throw new Exception('Invalid email address');
}
return preg_replace($this->pattern_replace, $this->replacement, $email);
}
}
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
Class | Loader | ||
![]() ![]() |
Lic. | Licence | ||
![]() |
Class | Class | ||
![]() ![]() |
Doc. | README | ||
![]() |
Class | Factory |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.