PHP - Limpiar inyección sql


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //mysqli_xxx
  2. function inSql($value){
  3. global $conn;
  4. if( get_magic_quotes_gpc() ) $value = stripslashes( $value );
  5. $value = mysqli_real_escape_string( $conn, $value );
  6. return $value;
  7. }
  8. #echo inSql("testeando '");
  9.  
  10. //mysql_xxx
  11. function inSql($value){
  12. global $conn;
  13. if( get_magic_quotes_gpc() ) $value = stripslashes( $value );
  14. $value = mysql_real_escape_string( $value );
  15. return $value;
  16. }
  17. #echo inSql("testeando '");
  18.  
  19. #Diferentes versiones de php:
  20. function inSql ($string) {
  21. global $conn,
  22. if(version_compare(phpversion(),"4.3.0")=="-1") {
  23. } elseif ($conn) {
  24. mysql_real_escape_string($string,$conn);
  25. } else { return false; }
  26. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.