Skip to content

Instantly share code, notes, and snippets.

@donpandix
Last active October 29, 2019 00:15
Show Gist options
  • Save donpandix/f1a90db1b6629cc46f3b to your computer and use it in GitHub Desktop.
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
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