I have an API server, and I need to put all get data into data base
i use this code after connect to database:
foreach ($_GET as $key => $value)
$_GET[$key] = mysql_real_escape_string($value);
Is my code safe?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, your code is not safe! Because we do not see how you put your data into your query – that’s the most important thing.
You can do so many things wrong, like this:
Only the last value is securely escaped, the first two are not!
Also,
mysql_real_escape_string()evaluates the encoding setting of an ongoing database connection. Have you connected to the database before? Have you set the encoding?Last: Do not escape stuff before you really need to. Premature escaping leads to all kind of problems because the pre-escaped data might be used for something else at the same time.