|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi, I was wondering,
By php.net manual, "Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods". Is there any way to override this problem? Just the not nice eval("return $variable");? and in simple words - is there any way to make the following code work: $varname = "\$_SERVER['REMOTE_ADDR']"; $varvalue = $$varname; ? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Greetings, "daniel danon".
In reply to Your message dated Saturday, October 11, 2008, 2:50:34, > By php.net manual, "Please note that variable variables cannot be used with > PHP's Superglobal arrays within functions or class methods". Is there any > way to override this problem? Just the not nice eval("return $variable");? > and in simple words - is there any way to make the following code work: > $varname = "\$_SERVER['REMOTE_ADDR']"; > $varvalue = $$varname; First of all, why you need it to work? Explain real case please. -- Sincerely Yours, ANR Daemon <anrdaemon@freemail.ru> |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
> $varname = "\$_SERVER['REMOTE_ADDR']";
> $varvalue = $$varname; That's wrong. Offhand you'll end up printing a string. I tried this: <?php $a = 365; $b = 366; $var = $_GET['var']; echo $$var; ?> And it was fine. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
That's fine as a test, but you never want to get a variable name from a
URL in practice. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com Richard Heyes wrote: >> $varname = "\$_SERVER['REMOTE_ADDR']"; >> $varvalue = $$varname; >> > > That's wrong. Offhand you'll end up printing a string. I tried this: > > <?php > $a = 365; > $b = 366; > > $var = $_GET['var']; > > echo $$var; > ?> > > And it was fine. > > |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> That's fine as a test, but you never want to get a variable name from a
> URL in practice. Of course you can, as long as it's sanitized and checked. -- Richard Heyes HTML5 Graphing for FF, Chrome, Opera and Safari: http://www.rgraph.org |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
I mean that it is open for hacking if you pass a variable name through a
URL. Thank you, Micah Gersten onShore Networks Internal Developer http://www.onshore.com daniel danon wrote: > What do you mean? > > On Sun, Oct 12, 2008 at 5:40 PM, Micah Gersten <micah@onshore.com > <mailto:micah@onshore.com>> wrote: > > That's fine as a test, but you never want to get a variable name > from a > URL in practice. > > Thank you, > Micah Gersten > onShore Networks > Internal Developer > http://www.onshore.com > > > > Richard Heyes wrote: > >> $varname = "\$_SERVER['REMOTE_ADDR']"; > >> $varvalue = $$varname; > >> > > > > That's wrong. Offhand you'll end up printing a string. I tried this: > > > > <?php > > $a = 365; > > $b = 366; > > > > $var = $_GET['var']; > > > > echo $$var; > > ?> > > > > And it was fine. > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > |
|
![]() |
| Outils de la discussion | |
|
|