Re: question about validation and sql injection
| From: | Chris | Date: | Fri, 16 May 2008 00:39:53 +0000 |
| Subject: | Re: question about validation and sql injection | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274400@lists.php.net to get a copy of this message | ||
Dmitri wrote:
> your validation looks good enough to me. If you only allow
> alphanumerical chars, then your should not be worried about sql injection
> also use addslashes($username) before you insert into database and you
> should be fine.
>
> Usually addslashes is enough to prevent this, but the validation that
> you have is also enough. So if you worried about the sql injection, then
> use both and you should be fine.
Ahh, that's just wrong.
I can encode an sql query into hex code and that'll pass alpha-numeric
validation.
Use mysql_real_escape_string when you save your data, or use
parameterized queries.
http://www.php.net/mysql_real_escape_string
http://www.php.net/manual/en/pdo.prepared-statements.php
http://www.php.net/manual/en/mysqli.prepare.php
--
Postgresql & php tutorials
http://www.designmagick.com/