1. Go to this page and download the library: Download sugiphp/filter 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/ */
// Validate integer from GET parameter - $_GET["key"].
// Default value is returned if the key is not found, or cannot be converted to an integer,
// or the value is outside the min / max range.
Filter::intGet($key, $min_range = false, $max_range = false, $default = false);
// for example if the URL is http://example.com?page=12
Filter::intGet("page", 1, false, 1); // returns 12
Filter::intGet("foo"); // returns FALSE
// Validate integer from POST parameter - $_POST["key"].
// Works like intGet()
Filter::intPost($key, $min_range = false, $max_range = false, $default = false);
// Validate integer from COOKIES - $_COOKIE[$key]
Filter::intCookie($key, $min_range = false, $max_range = false, $default = false);
// and from SESSION
Filter::intSession($key, $min_range = false, $max_range = false, $default = false);
Filter::str($value, $minLength = 0, $maxLength = false, $default = false);
// Examples:
Filter::str("a"); // "a"
Filter::str(1); // "1"
Filter::str(" a "); // "a"
Filter::str(""); // ""
Filter::str("", 1); // false
Filter::str(" a ", 1); // "a"
Filter::str("ab", 1, 1); // false
Filter::str("abc", 1, 2, "error"); // "error"
Filter::str("abc", 1, false, "error"); // "abc"
// Slightly different version of the Filter::str() method is Filter::plain()
// This will firstly strip all tags and then it will act exactly like Filter::str() method.
Filter::plain($value, $minLength = 0, $maxLength = false, $default = false);
Filter::url($value, $default = false);
// Examples:
Filter::url("http://igrivi.com"); // true
Filter::url("igrivi.com"); // false
Filter::url("http://localhost"); // false - The filter is mainly used for user inputs, so when we need URL, we intentionally don't want localhost
Filter::url("8.8.8.8"); // false
Filter::url("http://somedomain.com:81"); // true
Filter::url("http://somedomain.com:6"); // false