Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/05/2011, 17:03
Avatar de RichBoy
RichBoy
 
Fecha de Ingreso: agosto-2010
Mensajes: 177
Antigüedad: 13 años, 8 meses
Puntos: 7
Basta con esta funcion para evitar ataques sql?

Basta con esta funcion para evitar ataques sql por medio de las variables externas? solo para las variables externas, pues se que se puede por otros medios pero por el momento quiero saver si con esta funcion estamos seguros de que no van a inyectar algun codigo maligno atraves de las variable externas.


http://www.forosdelweb.com/f18/ejemp...4/#post2351131

Código PHP:
Ver original
  1. if (!function_exists("GetSQLValueString")) {
  2. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")  
  3. {
  4.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  5.  
  6.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  7.  
  8.   switch ($theType) {
  9.     case "text":
  10.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  11.       break;    
  12.     case "long":
  13.     case "int":
  14.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  15.       break;
  16.     case "double":
  17.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  18.       break;
  19.     case "date":
  20.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  21.       break;
  22.     case "defined":
  23.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  24.       break;
  25.   }
  26.   return $theValue;
  27. }
  28. }

ejemplo de llamando a la funcion:
Código PHP:
Ver original
  1. $variable=GetSQLValueString($_GET['Id'],"int");