Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/10/2008, 19:45
Roydan
 
Fecha de Ingreso: mayo-2007
Mensajes: 27
Antigüedad: 17 años
Puntos: 0
Pregunta Script para evitar SQL injection

Saludos

Navegando en internet encontre este codigo modificado de Dreamweaver para la funcion GetSQLValueString muy usada por DW

Código PHP:
<?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 
"text2":
      
$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;
    case 
"like":
      
$theValue = ($theValue != "") ? "'%" $theValue "%'" "NULL";
      break;
    case 
"likedespues":
      
$theValue = ($theValue != "") ? "'" $theValue "%'" "NULL";
      break;
    case 
"likeantes":
      
$theValue = ($theValue != "") ? "'%" $theValue "'" "NULL";
      break;
  }
  return 
$theValue;
}
}
?>
Creen que este completo y correcto? y cubra la mayoria de tipo de datos que pueden pasar como variables en mysql. No se mucho de php y quiero implementarlo en mi web