1

i'm using this in every $_get or $_post before acces or insert to my Database..

i'm sure it's not enough.. but how safe is it? can i combine it with some expresion to make it safer?

thanks a lot!

so how about this? mysql_real_escape_string(htmlspecialchars( $value ));

2
  • htmlspecialchars has nothing to do with making it safe for database entry. Use the database's escape function or parameterized queries (PDO) for that. Commented Jan 13, 2011 at 18:03
  • your change of subject and body makes the answers look inadequate: looks like you've asked "should I do A" and the answers are "no, you should do A". So I suggest that you revert your modifications. Commented Jan 13, 2011 at 19:30

3 Answers 3

5

No, that is not enough. You should use mysql_real_escape_string to prevent sql injection attacks.

Sign up to request clarification or add additional context in comments.

3 Comments

@Toni, yeah, it looks better. I would however save the raw values (eg. without using htmlspecialchars). When you retrieve the values and show them on some page you can use htmlspecialchars to prevent XSS attacks, but there is no need to save the string encoded.
so is thre a way to make a function like if(string_not_dangerous($string)){ save_normal_sting;} else { show(go_to_hell)} ?
i was considering Dreamweaver Replace all open documents: htmlspecialchars -> mysql_real_escape_string,
0

mysql_escape_string($value) is a bit smarter when sanitizing strings that will be used in an SQL query.

Comments

0

You should use mysql_real_escape_string() to protect your database from injection attacks (or better yet, prepared statements with something like the PDO library) and htmlspecialchars() when you're displaying data pulled from a database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.