Page 1 of 1
Getting form posted values using $var not $_POST['var']
Posted: Wed Dec 16, 2009 8:22 am
by Ruski
Hi friends,
I have a little problem. Just switched server and most of my code is broken due to a lot of form posted variables being retrived by using its variable name e.g:
and not
I was wandering what is the name of the php config that I can alter to enable my code to work in such a way again.
Thanks in advance
Re: Getting form posted values using $var not $_POST['var']
Posted: Wed Dec 16, 2009 8:44 am
by Turv
Ruski wrote:Hi friends,
I have a little problem. Just switched server and most of my code is broken due to a lot of form posted variables being retrived by using its variable name e.g:
and not
I was wandering what is the name of the php config that I can alter to enable my code to work in such a way again.
Thanks in advance
Code: Select all
foreach($_POST as $key => $val)
$$key = $val;
Put that at the top of your script somewhere and any values that are posted such as $_POST['variable'] will be accessible using $variable;
Re: Getting form posted values using $var not $_POST['var']
Posted: Wed Dec 16, 2009 9:27 am
by AbraCadaver
The setting in php.ini is register_globals. This is not safe to have on, especially if your code is not secure.
Rather than looping through the POST data, you can use that functions that were designed for this: import_request_variables() or extract(). This is just as insecure as register_globals though.
The loop is only handy if you do some validation/sanitizing there, which is probably a good idea.