Created
February 24, 2017 08:36
-
-
Save doulmi/822f9c08f988fd48b73ffad77a07a53d to your computer and use it in GitHub Desktop.
Protect from form input XSS attack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function stripXSS() | |
{ | |
$sanitized = static::cleanArray(Input::get()); | |
Input::merge($sanitized); | |
} | |
public static function cleanArray($array) | |
{ | |
$result = array(); | |
foreach ($array as $key => $value) { | |
$key = strip_tags($key); | |
if (is_array($value)) { | |
$result[$key] = static::cleanArray($value); | |
} else { | |
$result[$key] = trim(strip_tags($value)); // Remove trim() if you want to. | |
} | |
} | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment