Originally posted by Shawazi
$$key = addslashes($$key);
That depends on register_globals being enabled. If register_globals is off (which is the recommended setting, for security reasons) then your code won't work anymore.
Use this instead:
$_POST[$key] = addslashes($value);
Also, you might want to check the magic_quotes_gpc setting, and if it is enabled, skip the addslashes stuff, because PHP will have done it for you already.
My preferred way to handle form variables is to have a function that fetches them. So I type getvar('username') to the the username variable. Then I can do whatever I need in the getvar function (addslashes, check for nulls, etc). That is the most future-proof way to do it. If the PHP configuration changes with new and intersting input mangling, only that one function needs to be changed to make all of my code work.