Last active
October 29, 2019 00:15
-
-
Save donpandix/f1a90db1b6629cc46f3b to your computer and use it in GitHub Desktop.
Limpia parametros con PHP, evita inyección de código nocivo por URL
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
function limpiaParametros( $param ) { | |
$cross_site_scripting = array ( '@<script[^>]*?>.*?</script>@si', // Remover javascript | |
'@<[\/\!]*?[^<>]*?>@si' ); // Remover etiquetas HTML | |
$inyeccion_sql = array ( '/\bAND\b/i', '/\bOR\b/i', '/\bSELECT\b/i', | |
'/\bFROM\b/i', '/\bWHERE\b/i', '/\bUPDATE\b/i', | |
'/\bDELETE\b/i', '/\b\*\b/i', '/\bCREATE\b/i' ); | |
$retorno = preg_replace ( $inyeccion_sql, "", $param ); | |
$retorno = preg_replace ( $cross_site_scripting, "", $retorno ); | |
$retorno = htmlentities( $retorno, ENT_QUOTES ); // Acá es importante verificar la codificación (ISO o UTF-8) | |
return trim( $retorno ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment