Well, do you use stripslashes() because magic_quotes_gpc set? Thus, this code will only work when magic_quotes_gpc set! I would recommend that you disable it and not use the strislashes () call.
But note that there is nothing like "universal sanitation." Let him just quote, because it's all about him.
When quoting, you always quote text for a specific output , for example:
- string value for mysql query
like expression for mysql query- html code
- Json
- mysql regex
- php regex
For each case, you need a different quote, because each use is present in a different syntax context. This also implies that quoting should not be done at the input to PHP, but at a specific output ! What is the reason why functions like magic_quotes_gpc are broken (always make sure they are turned off !!!).
So, what methods can be used for citation in these specific cases? (Feel free to correct me, there may be more modern methods, but they work for me)
mysql_real_escape_string($str)mysql_real_escape_string(addcslashes($str, "%_"))htmlspecialchars($str)json_encode() - only for utf8! I use my function for iso-8859-2mysql_real_escape_string(addcslashes($str, '^.[]$()|*+?{}')) - you cannot use preg_quote in this case, because the backslash will be reset twice!preg_quote()
source share