Member-only story
Bypass mysql_real_escape_string and addslashes from Injection Attacks
In this article, I will talk about the mysql_real_escape_string bypass defense method. It is not recommended to try to bypass security measures such as mysql_real_escape_string
or addslashes
as they are in place to protect against injection attacks. Injection attacks occur when an attacker is able to send malicious data to a web application, which is then executed by the application as part of a command or query. This can allow the attacker to gain unauthorized access to sensitive information, modify or delete data, or perform other malicious actions.
Instead of trying to bypass these security measures, it is important to use them properly to protect against injection attacks. mysql_real_escape_string
and addslashes
are functions that can be used to sanitize user input by escaping special characters that have a special meaning in SQL. This helps to prevent injection attacks by ensuring that any user-supplied input is treated as a string rather than being interpreted as part of a command or query.
To use mysql_real_escape_string
, you should first establish a connection to the MySQL database using the mysql_connect
function. Then, you can use mysql_real_escape_string
to escape any user-supplied input before using it in a SQL query. For example:
$conn = mysql_connect($host, $user, $password);
$safe_input = mysql_real_escape_string($_POST['input']);
$query = "SELECT * FROM users WHERE username='$safe_input'";
addslashes
works similarly, but it is not specific to MySQL and can be used with other databases as well. It escapes special characters by adding backslashes before them. For example:
$safe_input = addslashes($_POST['input']);
$query = "SELECT * FROM users WHERE username='$safe_input'";
It is important to note that both mysql_real_escape_string
and addslashes
have been deprecated as of PHP 7.4 and should no longer be used. Instead, you should use prepared statements and parameterized queries, which are more secure and easier to use. Prepared statements allow you to separate the data from the query, and the database engine automatically handles the proper escaping of the data.
In summary, trying to bypass security measures such as mysql_real_escape_string
and addslashes
is not a good idea as it can leave your application vulnerable to injection attacks. Instead, you should use prepared statements and parameterized queries to protect against these types of attacks.

In this article, I have been talking about the mysql_real_escape_string bypass defence method. Take care and see you in my next post.