note 89279 deleted from function.mysql-real-escape-string by aidan

From: Date: Sun, 24 May 2009 19:40:49 +0000
Subject: note 89279 deleted from function.mysql-real-escape-string by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155927@lists.php.net to get a copy of this message
Note Submitter: LPChip ---- Please note that mysql_real_escape_string() will not escape the char ` ([to the] left of the 1 [on US keyboards]) which is often used in queries. An example: <?php $username = $_POST['username']; $password = $_POST['password']; //the user submitted the following: $username = 'foobar` --'; $myQuery = sprintf( 'SELECT * FROM my_table WHERE username = %s AND password = %s--', mysql_real_escape_string($username), mysql_real_escape_string($password) ); //$myQuery will now be: SELECT * FROM my_table WHERE username = foobar -- AND password = `-- //Which is equal to : SELECT * FROM my_table WHERE username = foobar ?> This will actually parse without a problem and you have an SQL injection. To combat this, you should also str_replace the sign for \.

« previous php.notes (#155927) next »