Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/11/2008, 14:57
bocasecaman
 
Fecha de Ingreso: agosto-2007
Mensajes: 101
Antigüedad: 16 años, 8 meses
Puntos: 1
Pregunta Me lo podeis explicar??

Hola a todos, buscando en este foro (antes de postear a lo loco, mas de uno me lo agradecera) sobre la seguridad para evitar las temidas inyecciones sql, me tope con este codigo:

usa esta funcion para todas las variables externas $_GET $_POST $_COOKIE etc...

Código PHP:

Código PHP
:

if (!
function_exists("GetSQLValueString")) { 
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "")  

  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

  switch (
$theType) { 
    case 
"text"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break;     
    case 
"long"
    case 
"int"
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL"
      break; 
    case 
"double"
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL"
      break; 
    case 
"date"
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL"
      break; 
    case 
"defined"
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue
      break; 
  } 
  return 
$theValue


ejemplo de llamando a la funcion:

Código PHP:
$variable=GetSQLValueString($_GET['Id'],"int"); 
Mi pregunta es: ¿alquien me lo puede explicar como funciona y que debo modificar? Supuestamente sirve para eliminar las comillas y codigo malicioso que intenta hacerse pasar por usuario.
Gracias por lo menos por leer ;)