Ver Mensaje Individual
  #15 (permalink)  
Antiguo 05/05/2011, 02:07
Avatar de s00rk
s00rk
 
Fecha de Ingreso: octubre-2010
Ubicación: Mexico
Mensajes: 238
Antigüedad: 13 años, 5 meses
Puntos: 48
Respuesta: buscar registro en la base de datos

Bueno aqui te dejo mi antisql, para limpiar la variable n.n

Código PHP:
Ver original
  1. function clean($value)
  2. {
  3.         $check = $value;
  4.  
  5.         $search = array('chr(', 'chr=', 'chr%20', '%20chr', 'wget%20', '%20wget', 'wget(',
  6.         'cmd=', '%20cmd', 'cmd%20', 'rush=', '%20rush', 'rush%20',
  7.         'union%20', '%20union', 'union(', 'union=', 'echr(', '%20echr', 'echr%20', 'echr=',
  8.         'esystem(', 'esystem%20', 'cp%20', '%20cp', 'cp(', 'mdir%20', '%20mdir', 'mdir(',
  9.         'mcd%20', 'mrd%20', 'rm%20', '%20mcd', '%20mrd', '%20rm',
  10.         'mcd(', 'mrd(', 'rm(', 'mcd=', 'mrd=', 'mv%20', 'rmdir%20', 'mv(', 'rmdir(',
  11.         'chmod(', 'chmod%20', '%20chmod', 'chmod(', 'chmod=', 'chown%20', 'chgrp%20', 'chown(', 'chgrp(',
  12.         'locate%20', 'grep%20', 'locate(', 'grep(', 'diff%20', 'kill%20', 'kill(', 'killall',
  13.         'passwd%20', '%20passwd', 'passwd(', 'telnet%20', 'vi(', 'vi%20',
  14.         'insert%20into', 'select%20', 'fopen', 'fwrite', '%20like', 'like%20',
  15.         '$_request', '$_get', '$request', '$get', '.system', 'HTTP_PHP', '&aim', '%20getenv', 'getenv%20',
  16.         'new_password', '&icq','/etc/password','/etc/shadow', '/etc/groups', '/etc/gshadow',
  17.         'HTTP_USER_AGENT', 'HTTP_HOST', '/bin/ps', 'wget%20', 'uname\x20-a', '/usr/bin/id',
  18.         '/bin/echo', '/bin/kill', '/bin/', '/chgrp', '/chown', '/usr/bin', 'g\+\+', 'bin/python',
  19.         'bin/tclsh', 'bin/nasm', 'perl%20', 'traceroute%20', 'ping%20', '.pl', 'lsof%20',
  20.         '/bin/mail', '.conf', 'motd%20', 'HTTP/1.', '.inc.php', 'config.php', 'cgi-', '.eml',
  21.         'file\://', 'window.open', '<script>', 'javascript\://','img src', 'img%20src','.jsp','ftp.exe',
  22.         'xp_enumdsn', 'xp_availablemedia', 'xp_filelist', 'xp_cmdshell', 'nc.exe', '.htpasswd',
  23.         'servlet', '/etc/passwd', 'wwwacl', '~root', '~ftp', '.js', '.jsp', 'admin_', '.history',
  24.         'bash_history', '.bash_history', '~nobody', 'server-info', 'server-status', 'reboot%20', 'halt%20',
  25.         'powerdown%20', '/home/ftp', '/home/www', 'secure_site, ok', 'chunked', 'org.apache', '/servlet/con',
  26.         '<script', 'UPDATE', 'SELECT', 'DROP', '/robot.txt' ,'/perl' ,'mod_gzip_status', 'db_mysql.inc', '.inc', 'select%20from',
  27.         'select from', 'drop%20', 'getenv', 'http_', '_php', 'php_', 'phpinfo()', '<?php', '?>', 'sql=');
  28.  
  29.         $value = str_replace($search, '', $value);
  30.  
  31.         $value = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$value);
  32.         $value = trim($value);
  33.         $value = strip_tags($value);
  34.         $value = addslashes($value);
  35.         $value = str_replace("'", "''", $value);
  36.  
  37.         if( $check != $value )
  38.         {
  39.             $logf = fopen("./sql.txt", "a+");
  40.             fprintf($logf, "%s - Fecha: %s IP: %s Valor: %s, Corregido: %s\r\n", $_SERVER[PHP_SELF], date("d-m-Y h:i:s A"), $_SERVER['REMOTE_ADDR'], $check, $value );
  41.             fclose($logf);
  42.             alertbox("Que intentas hacer? (: , Mejor mira esto xD", "http://www.google.com/");
  43.              
  44.         }
  45.  
  46.         return( $value );
  47. }
  48.  
  49. if(!function_exists("alertbox")){
  50. function alertbox($text, $url)
  51. {
  52.     echo "<body  bgcolor='#000000'><script>alert('$text');document.location = '$url'</script></body>";
  53.     die("Javascript disabled");
  54. } }

Y ya pues solamente am ya te explicarion lo de
$nombre = $_POST["nombre"];

entonces para limpiar la variable hariamos esto solamente
Código PHP:
Ver original
  1. $nombre = clean($_POST["nombre"]);
  2.     $sql = "SELECT * FROM personas WHERE LOWER(nombre) = '%$nombre%';

Ahi espero explicarme n_n, cualquier duda aqui estamos :P