![]() |
$_POST: Are both approaches equally good?
Take a look at the code below regarding POST. Which is better?
PHP Code:
|
They're both equally bad from the perspective of SQL injection: http://en.wikipedia.org/wiki/SQL_injection
Even if there's no intentional SQL injection your query will error out if any of the submitted data contains a " in the first example or a ' in the second. Once you've learned about escaping user submitted data, I would recommend *not* using extract. The PHP manual page itself ( http://www.php.net/extract ) recommends "Do not use extract() on untrusted data, like user input (i.e. $_GET, $_FILES, etc.)" There's no sense using extract() anyway, and it may overwrite variables you have already set up, further opening your code up to abuse. |
Thanks. I had read the PHP manual advisory previously, but since then I have also read a couple of blogs about how great extract() was. But I hadn't thought about it overwriting existing variables, which is not a good thing.
Dave |
Funnily enough I've just read a post which talks about SQL injection along with some examples: http://blog.tuvinh.com/top-7-php-security-blunders/
Some other useful stuff in there too. |
Quote:
|
Quote:
|
Extract is a handy little fella in some situations, no sense in ruling it out; I've written numerous functions in the past where I wanted/needed to return multiple arrays of data. Nest the arrays, return it, and extract it on the other side into it's components. No fuss.
|
| All times are GMT. The time now is 05:40 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0