Skip to content

Instantly share code, notes, and snippets.

@rafaelfoster
Forked from danilowm/gist:1997988
Last active December 27, 2015 15:19
Show Gist options
  • Save rafaelfoster/7346969 to your computer and use it in GitHub Desktop.
Save rafaelfoster/7346969 to your computer and use it in GitHub Desktop.
Function in PHP that receives the parameters (normaly passed by a $_POST or a $_GET and treat the informations removing some SQL commands, preventing the SQL Injection
<?php
/*
* Anti Injection
* Verifica e Trata as informações
* Autor: Danilo Iannone - [email protected]
*/
function anti_injection( $obj ) {
$obj = preg_replace("/(from|alter table|select|insert|delete|update|where|drop table|show tables|#|\*|--)/i", "",strtolower($obj));
$obj = trim($obj);
$obj = strip_tags($obj);
if(!get_magic_quotes_gpc()) {
$obj = addslashes($obj);
return $obj;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment