How to install and use PhpSanitization

This is where you share YOUR scripts with others

Moderators: egami, macek, gesf

Post Reply
User avatar
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Feb 06, 2021 4:53 pm

Sat Feb 06, 2021 5:06 pm

​Hey PHP Forum Members.

In this simple article, I will explain how to install and use PhpSanitization.

But I will tell you what is PhpSanitization how can it help you.

What is PhpSanitization

PhpSanitization is a simple class that can verify and clean values to assure they are valid.

It can take a given string and remove or encode certain types of text values, so it can be displayed on Web pages lowering the risk of being used to perform security attacks.

The class can also sanitize arrays of data by processing the array values one by one.


1. Out-Of-The-Box.
2. Support String, Arrays, and Associative Arrays.
3. Escape PDO and SQL queries.
4. Easy to Use.

How to Install

First, you need to install the composer before installing it.

You can install Composer simply from here Composer.

Code: Select all

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
After installing composer now you will be able to install PhpSanitization.

Cd to your project folder using the terminal after that use this command to install the project using composer.

Code: Select all

composer require phpsanitization/phpsanitization
How to use

The usage of the project is simple.

In your form handler add this block of code to sanitize any POST request.

Code: Select all

include_once 'vendor/autoload.php';

use PhpSanitization\PhpSanitization\Sanitization;

$s = new Sanitization();

$post = $s->useSanitize($_POST);

The documentation for PhpSanitization is available here.

In the End

If you have any idea or like to contribute please do.


To download the project source code from here.
php-forum Fan User
php-forum Fan User
Posts: 127
Joined: Mon Jun 08, 2020 2:00 am

Sun Feb 07, 2021 10:22 am

The documentation you've put together is nice.

However, a lot of this code is just wrapping built in PHP functions; those bits are kinda useless.

You also attempt to provide escaping functionality for database queries; that's dangerous. PHP's database libraries have built in methods for preparing queries, they will always be far better than anything you make for yourself.
User avatar
php-forum GURU
php-forum GURU
Posts: 412
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI

Sun Feb 07, 2021 3:41 pm

Someone told me a long time ago that creating you sanitation is a fruitless adventure as it even takes years for expertise to develop and to get it right. Event then they have made big mistakes
in security. While your intentions are good the results were probably in vain.
Life is a fig newton of your imagination!
Post Reply