es opcionar pero podrias validar el tipo de dato y la longitud...
Código PHP:
if (!function_exists("seguridad")) {
function seguridad($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "", $tamanomax)
{
// longitud del texto
$theValue=substr($theValue, 0, $tamanomax);
// contra inyeccion sql
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
// tipo de dato
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "text2":
$theValue = ($theValue != "") ? "" . $theValue . "" : "";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "intonulo":
$theValue = ($theValue != "") ? intval($theValue) : "";
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;
}
}
Como usar:
Código PHP:
<?php
// variable, tipo de dato, longitud maxima
$dato=seguridad($_POST['variable'],"int",10);
?>