diff --git a/reference/strings/functions/addslashes.xml b/reference/strings/functions/addslashes.xml index e1fbba8576..2d1ec83611 100644 --- a/reference/strings/functions/addslashes.xml +++ b/reference/strings/functions/addslashes.xml @@ -13,34 +13,44 @@ stringstr - Returns a string with backslashes before characters that need - to be quoted in database queries etc. These characters are - single quote ('), double quote - ("), backslash (\) - and NUL (the &null; byte). + Returns a string with backslashes before characters that need to be + quoted. These characters are single quote ('), + double quote ("), backslash + (\) and NUL (the &null; byte). An example use of addslashes is when you're - entering data into a database. For example, to insert the name - O'reilly into a database, you will need to escape - it. It's highly recommended to use DBMS specific escape function + entering data into string that is evaluated by PHP. For example, + O'reilly is stored in $str, you need to escape + $str. (e.g. eval("echo '".addslashes($str)."';"); ) + + + To escape database parameters, DBMS specific escape function (e.g. mysqli_real_escape_string for MySQL or - pg_escape_string for PostgreSQL), but - if the DBMS you're using doesn't have an escape function - and the DBMS uses \ to escape special chars, - you can use this function. This would only be to get the data - into the database, the extra \ will not be inserted. - Having the PHP directive - magic_quotes_sybase set to on will mean - ' is instead escaped with another - '. + pg_escape_literal, pg_escape_string + for PostgreSQL) should be used for security reasons. DBMSes have + differect escape specification for identifiers (e.g. Table name, + field name) than parameters. Some DBMS such as PostgreSQL provides + identifier escape + function, pg_escape_indentifier, but not all + DBMS provides identifier escape API. If this is the case, refer to + your database system manual for proper escaping method. + + + If your DBMS doesn't have an escape function and the DBMS + uses \ to escape special chars, you might be + able use this function only when this escape method is adequate for + your database. Please note that use + of addslashes for database parameter escaping + can be cause of security issues on most databases. The PHP directive - magic_quotes_gpc was on by default before PHP 5.4, and it - essentially ran addslashes on all GET, POST, - and COOKIE data. Do not use addslashes on - strings that have already been escaped with + magic_quotes_gpc was on by default before + PHP 5.4, and it essentially ran addslashes on + all GET, POST, and COOKIE data. Do not + use addslashes on strings that have already + been escaped with magic_quotes_gpc as you'll then do double escaping. The function get_magic_quotes_gpc may come in handy for @@ -89,7 +99,7 @@ echo addslashes($str); - + &reftitle.seealso;