PDA

View Full Version : PHP: addslashes();


Valerij
12-16-2008, 08:36 PM
Hi guys,
I'm having problems with PHP addslashes() function. Its a function that is meant to protect database from injections by adding slashes. In PHP manual;
http://no.php.net/manual/en/function.addslashes.php
It says: "This would only be to get the data into the database, the extra \ will not be inserted."

For some reason this is not what happens in my case, I get 1 extra slash which then goes to the database... Why? Should I use stripslashes() function to get rid of them? I mean.. Its not supposed to be this way...

yell0wdart
12-17-2008, 03:40 PM
Personally, I'd keep escaping my strings when going into the database, and strip them if I'm outputting them to HTML.

Rather than addslashes(), though, from a security standpoint, you'll be MUCH better off using mysql_real_escape_string(): http://no.php.net/manual/en/function.mysql-real-escape-string.php