1. Go to this page and download the library: Download rancoud/security library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rancoud / security example snippets
composer
use Rancoud\Security\Security;
// When you want to escape text for HTML output.
echo '<p>' . Security::escHTML('<script>alert("test");</script>') . '</p>' . "\n";
// -> <p><script>alert("test");</script></p>
// When you want to escape text for HTML attribute output.
echo '<div data-attr="' . Security::escAttr('my-data"><script>alert("test");</script><div hidden="') . '">' . "\n";
// -> <div data-attr="my-data"><script>alert("test");</script><div hidden=""></div>
// When you want to escape text for JS output.
echo 'const value = "' . Security::escJS('";alert("test");let a="') . '";' . "\n";
// -> const value = "\x22\x3Balert\x28\x22test\x22\x29\x3Blet\x20a\x3D\x22";
// When you want to escape text for URL output.
echo Security::escURL('https://example.com') . "\n";
// -> https%3A%2F%2Fexample.com
// When you want to escape text for CSS output.
echo 'body {background-color: ' . Security::escCSS('red;} body {background-image: url("https://example.com");') . '}' . "\n";
// -> body {background-color: red\3B \7D \20 body\20 \7B background\2D image\3A \20 url\28 \22 https\3A \2F \2F example\2E com\22 \29 \3B }
// Checks if charset is supported.
Security::isSupportedCharset('ISO-8859-15');
// -> true
Security::isSupportedCharset('foo');
// -> false
public static function escHTML($text, string $charset = 'UTF-8'): string
public static function escAttr($text, string $charset = 'UTF-8'): string
public static function escJS($text, string $charset = 'UTF-8'): string
public static function escURL($text, string $charset = 'UTF-8'): string
public static function escCSS($text, string $charset = 'UTF-8'): string
public static function isSupportedCharset(string $charset): bool
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.