Re: $$key = $value?



On Mar 24, 5:21 am, Gilles Ganault <nos...@xxxxxxxxxx> wrote:
Hello

I'm reading articles on how to validate forms, and happened on the
following section:

foreach($_POST as $key=>$value) {
$$key = $value;
}

http://www.phphacks.com/content/view/31/33/

What does "$$key=$value" do?

Thank you.

$$key is a variable variable:
http://us3.php.net/language.variables.variable

Basically what this does is sets a variable name with the key in
$__POST as the name. For example, if your $_POST superglobal looked
like:

$_POST = array ( 'firstName' => 'Steve',
'usenet'=> 'ElintPimp');

Than you run it through this function, it produces tow variables:
$fistName = 'Steve';
$usenet = 'ElintPimp';

Two problems with this function:
1) There is a function to do this - extract()
http://us3.php.net/manual/en/function.extract.php
2) Both what that foreach loop and the extract() function are
potential security problems. I'll copy what is said about this from
php.net:

"Do not use extract() on untrusted data, like user-input ($_GET, ...).
If you do, for example, if you want to run old code that relies on
register_globals temporarily, make sure you use one of the non-
overwriting extract_type values such as EXTR_SKIP and be aware that
you should extract in the same order that's defined in variables_order
within the php.ini."

Regards,

Steve
.



Relevant Pages

  • Could not initialize class question
    ... Could someone tell me what this error - below - means (eg a jar file can't be seen, a dll can't be retrieved, something missing on the server, something missing on the client browser, etc). ... I've developed a jogl applet that runs in Eclipse (on a Windows machine). ... VALIDATE: gluegen-rt.dll ... EXTRACT: gluegen-rt.dll ...
    (comp.lang.java.help)
  • Re: How to display HTML that is the data within and XML file.
    ... I need to validate by doing something locally. ... by a browser is hardly a way to "validate" the HTML. ... browsers can/will show the same markup differently, ... So if I use a browser and XSLT to extract that data it gets treated as ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: [Full-Disclosure] Administrivia: List Compromised due to Mailman Vulnerability
    ... >Subscriber addresses and passwords have been compromised. ... but better is to extract and validate the tail of ...
    (Full-Disclosure)
  • Re: Text function MID, RIGHT, LEN
    ... Validate with Sfift+Ctrl+enterr ... I try to extract part of a text: ... SAVANNAH CHARD FLO-FAIRTRADE BIB, 200 CL ... Someone who now how I can fix this? ...
    (microsoft.public.excel.misc)
  • Hough Transform for rectangle
    ... I am a amateur playing around with hough transform developing in ... I have managed to create sub-routines to extract lines and ... circle from reading articles in the net. ...
    (sci.image.processing)