irwan

PHP : Basic Prevent SQL Injection

Mar 16th, 2012
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. <?php
  2. function sql_sanitize( $sCode ) {
  3.         // If PHP version > 4.3.0
  4.     if ( function_exists( "mysql_real_escape_string" ) ) {
  5.                 // Escape the MySQL string.
  6.         $sCode = mysql_real_escape_string( $sCode );
  7.         // If PHP version < 4.3.0
  8.     } else {
  9.                 // Precede sensitive characters with a backslash \
  10.         $sCode = addslashes( $sCode );
  11.     }
  12.         // Return the sanitized code
  13.     return $sCode;
  14. }
  15. ?>
Advertisement
Add Comment
Please, Sign In to add comment