Answer the question
In order to leave comments, you need to log in
What kind of incoming data filtering do you perform?
I have been doing web development for many years and for login I allow only letters, numbers and spaces, and I don’t limit or filter the password.
What methods do you use to protect against SQL injections in:
login
password
article title (is it without html, strip_tags and addslashes enough?)
article
content (only addslashes?)
for example)?
Thanks a lot.
Answer the question
In order to leave comments, you need to log in
restricting users in what characters they want to use is stupid.
The problem of sql injections in the context of php is solved using pdo + prepared statements.
The XSS problem is solved by escaping (htmlentities). It's easier to use templating engines like twig, which by default will escape all output data.
In general, I think you should take some popular framework (doctrine2, silex, etc.) and not worry about most of these problems.
When adding data to the database, to prevent SQL injection, we pass all data through mysql_real_escape_string :
function sanitize($string) {
return "'" . mysql_real_escape_string($string) . "'";
}
$query = sql_sprintf(
"SELECT * FROM users WHERE user=%s AND mail=%s",
sanitize($_POST['login']),
sanitize($_POST['mail'])
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question