Skip to content

Latest commit

 

History

History
112 lines (75 loc) · 2.28 KB

USAGE_FILTER.md

File metadata and controls

112 lines (75 loc) · 2.28 KB

Using Filters Usage

Other Links

Fake Data

// Generate Fake post Data

$object = new stdClass();
$object->name = "delete";
$object->data = (object) array("age"=>21,"bad"=>"<b>Bad</b>");

$_POST = array();
$_POST['testing']["name"] = "<b>" . $_SERVER['SERVER_NAME'] . "</b>";
$_POST['testing']["example"]['xss'] = '<IMG SRC=javascript:alert("XSS")>';
$_POST['testing']["example"]['sql'] = "x' AND email IS NULL; --";
$_POST['testing']["example"]['filter'] = "Let's meet  4:30am Ât the \tcafé\n";
$_POST['selected'] = "ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂHello WorldÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ";
$_POST['phone'] = "Phone+888(008)9903";
$_POST['hello'] = "Hello word";
$_POST['image'] = file_get_contents("http://i.imgur.com/YRz0AI7.png");
$_POST['binary'] = mcrypt_create_iv(10, MCRYPT_DEV_URANDOM);
$_POST['object'] = $object ;

Basic Usage

You call easily filter out XSS Injection ```PHP $_POST = new Varriable($_POST); $_POST->setFilter(new Basic(Basic::FILTER_XSS)); print_r($_POST['testing']['example']); ```

Output

Array
(
    [xss] => &lt;IMG SRC=javascript:alert(&quot;XSS&quot;)&gt;
    [sql] => x&#039; AND email IS NULL; --
    [filter] => 
)

Filter Specific Key

You can restrict modification to your varriables.
//Before 
echo $_POST['phone'];

//Convert post to super
$_POST = new Varriable($_POST);
$_POST->offsetFilter("phone", new Basic(Basic::FILTER_INT));

//After 
echo $_POST->phone;

Output

Phone+888(008)9903  //before
+8880089903         //after 

Filter IGNORE

During filter process Ignore Binray , Hash (md5 , sha ) during Filter

$_POST = new Varriable($_POST);
$_POST->setFilter(new Basic(Basic::FILTER_ALL,
		 Basic::IGNORE_BASE64 | Basic::IGNORE_HEX | Basic::IGNORE_BINARY));

Callback

You can use Callback which also supports Regex.

$callback = new Callback();

// Add callback to keys when found
$callback->add("hello", function ($value, $key) {
    return strtoupper($value);
});

// You can also use regex with match
$callback->match("/^hello/", function ($value, $key) {
    return strtoupper($value);
});

$_POST = new Varriable($_POST, $callback);
echo $_POST['hello'];

Output

HELLO