Sanitize and escape every values in your PHP Application

Overview

PHP Sanitizer

Sanitize and escape every values in your PHP Application.


This solution will make PHP developer life easy, very easy and developers would be able to create a secure application quickly and effortlessly.

Let's see inside of this.

Requirement

  • PHP: 7.1 or later
  • PHP Unit (in dev): 7

Latest Version

0.0.7

How to install

composer require maniruzzaman/sanitizer

Documentation

Instantiation and loading.

// at top of the class autoload
use Maniruzzaman\Sanitizer\Sanitize;

// instantiate anywhere if needed
$sanitize = new Sanitize();

Sanitize Text

Example 1: Sanitize text with script:

$string  = 'Text with script <script>alert("you are hacked...")</script>';
Sanitize::text($string);
#Output: Text with issuealert(&quot;you are hacked...&quot;)

Example 2: Sanitize text with html texts:

$string  = 'Text with script <strong>This is strong text</strong>';
Sanitize::text($string);
#Output: Text with script This is strong text

Sanitize Attribute

Example 3: Sanitize attribute to filter out unnecessary strings:

$string  = 'https://devsenv.com<script>welcome</script>';

$sanitize = new Sanitize();
$sanitize->attr($string);
#Output: https:://devsenv.com

More is coming...

Testing

We've used PHPUnit to test our codes.

Check if everything passes test cases or not. You can check our test cases to see the implementations of Sanitizer.

// For full directory
phpunit tests

// For specific file test
phpunit tests/SanitizeTest.php

Release Notes:

Release version 0.0.7

  • [Enhancement] Added unit test for text() helper sanitize function.
  • [Enhancement] Added some security and fund links

Release version 0.0.6

  • [Enhancement] Updated some doc-block
  • [Enhancement] Structured some code base
  • [Enhancement] Updated Minimum PHP Version requirement
  • [Enhancement] Added PHP Unit test support dev package

Release version 0.0.5

  • Fixed some autoloading issue with documenting

Release version 0.0.4

  • Fixed autoloading functions

Release version 0.0.3

  • Removed some unused autoload dependency

Release version 0.0.2

  • Added Url Sanitization

Release version 0.0.1

  • Release some simple escaping functions.
  • Added text sanitization
  • Added attribute sanitization

License

The Library is open-sourced software licensed under the MIT license.

Support

Do you wanna support me to buy a coffee? Please be one of my patreon - https://www.patreon.com/maniruzzaman

You might also like...
The Barista explores every Latte (file) for strict quality, helps with Latte 2 to 3 upgrade

The Barista makes Your Perfectly Tasty Latte Do you drink Latte with your templates? Get it from Barista that knows his job: explore Latte via node vi

This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api)
This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api)

Validator-Class This Validate Class is for those who are looking for a validator that returns a code for every each error (Laravel/Api) Requirements A

Read and show values from form valid

read-and-show-values-from-form-valid Escribe un programa PHP que permita al usuario rellenar un formulario de registro con los datos de nombre, contra

Provides the functionality to compare PHP values for equality.

sebastian/comparator This component provides the functionality to compare PHP values for equality. Installation You can add this library as a local, p

A PHP library to write values to .env (DotEnv) files

DotEnvWriter A PHP library to write values to .env (DotEnv) files Installation DotEnvWriter can be installed with Composer. composer require mirazmac/

Humanize values that are readable only for developers.

PHP Humanizer Tests - 4.x Readme for 4.x version Humanize values to make them readable for regular people ;) Installation Run the following command: c

Google-like values converter

Google-like values converter. Support for different types of conversions, for examples: 1 kilometer - meters 1 dollar - THB 1 kilogram - meters ...

Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.DeepEqual().

Deeper Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.De

Composer plugin replacing placeholders in the scripts section by dynamic values

Composer Substitution Plugin The Composer Substitution plugin replaces placeholders in the scripts section by dynamic values. It also permits to cache

Comments
  • Using the assertSame to make assert equals strict

    Using the assertSame to make assert equals strict

    Changed log

    • As title, using the assertSame to replace assertEquals and make these assertions strict.
    • Removing the $this->assertEquals("Test", "Test"); assertion tests.
    opened by peter279k 0
  • Remove cached dependencies file and add PHPUnit 8

    Remove cached dependencies file and add PHPUnit 8

    Changed log

    • When the composer.lock is existed, it always modified this cached file when running the composer update command.
    • If the cached dependencies are not supported for the PHP version, it needs to run the composer update command.
    • Removing the composer.lock file can always get the latest dependencies.
    • Here is the example to describe that:
    localadmin@clickhouse02:~/sanitizer$ php ~/composer.phar install
    Installing dependencies from lock file (including require-dev)
    Verifying lock file contents can be installed on current platform.
    Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`.
    Your lock file does not contain a compatible set of packages. Please run composer update.
    
      Problem 1
        - phar-io/manifest is locked to version 1.0.3 and an update of this package was not requested.
        - phar-io/manifest 1.0.3 requires php ^5.6 || ^7.0 -> your php version (8.1.9) does not satisfy that requirement.
      Problem 2
        - phar-io/version is locked to version 2.0.1 and an update of this package was not requested.
        - phar-io/version 2.0.1 requires php ^5.6 || ^7.0 -> your php version (8.1.9) does not satisfy that requirement.
      Problem 3
        - phpunit/php-code-coverage is locked to version 6.1.4 and an update of this package was not requested.
        - phpunit/php-code-coverage 6.1.4 requires php ^7.1 -> your php version (8.1.9) does not satisfy that requirement.
      Problem 4
        - phpunit/phpunit is locked to version 7.5.20 and an update of this package was not requested.
        - phpunit/phpunit 7.5.20 requires php ^7.1 -> your php version (8.1.9) does not satisfy that requirement.
      Problem 5
        - sebastian/global-state is locked to version 2.0.0 and an update of this package was not requested.
        - sebastian/global-state 2.0.0 requires php ^7.0 -> your php version (8.1.9) does not satisfy that requirement.
    
    • When running the composer update command, it will have the following error:
    localadmin@clickhouse02:~/sanitizer$ php ~/composer.phar update
    Loading composer repositories with package information
    Info from https://repo.packagist.org: #StandWithUkraine
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - phpunit/phpunit[7.0.0, ..., 7.5.20] require php ^7.1 -> your php version (8.1.9) does not satisfy that requirement.
        - Root composer.json requires phpunit/phpunit ^7 -> satisfiable by phpunit/phpunit[7.0.0, ..., 7.5.20].
    
    • To resolve the above error, it should be great to add the PHPUnit 8 inside the require-dev block in composer.json file.
    opened by peter279k 0
Releases(0.0.7)
Owner
Maniruzzaman Akash
System Designer & Architect. Can develop/architect your system's Frontend with React/Vue and Backend with Laravel/Node JS. Interested to work with AI too...
Maniruzzaman Akash
Dobren Dragojević 6 Jun 11, 2023
Sanitize untrustworthy HTML user input (Symfony integration for https://github.com/tgalopin/html-sanitizer)

html-sanitizer is a library aiming at handling, cleaning and sanitizing HTML sent by external users (who you cannot trust), allowing you to store it and display it safely. It has sensible defaults to provide a great developer experience while still being entierely configurable.

Titouan Galopin 86 Oct 5, 2022
Adds a header to every response to try and twart Google's usage of your site in it's FLoC tracking method.

Laravel No FLoC This package will add the Permissions-Policy: interest-cohort=() to try and twart Google's usage of your site in it's FLoC tracking me

Jean-Philippe Murray 11 Jul 14, 2022
Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

JBZoo Toolbox 786 Dec 30, 2022
JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

JSONFinder - a library that can find json values in a mixed text or html documents, can filter and search the json tree, and converts php objects to json without 'ext-json' extension.

Eboubaker Eboubaker 2 Jul 31, 2022
This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every translatable field.

Autotranslate This module integrates Silverstripe CMS with Google Translate API and then allows content editors to use automatic translation for every

null 4 Jan 3, 2022
Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda.

Our Wedding Website Because every Wedding RSVP website needs to follow DDD, CQRS, Hexagonal Architecture, Event Sourcing, and be deployed on Lambda. ?

Edd Mann 3 Aug 21, 2022
This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

This library provides a collection of native enum utilities (traits) which you almost always need in every PHP project.

DIVE 20 Nov 11, 2022
SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someone

SlimJim WHY? SlimJim was born out of a need for a simple auto update script which would update multiple development/test environments every time someo

Jesal Gadhia 100 Apr 22, 2022
A widget that displays a Bible verse every day in the Statamic dashboard

Statamic Widget: Verse of the Day What is it A widget that displays a Bible verse every day in the Statamic dashboard. How to install it Install via c

Michael 2 Jan 27, 2022