By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,215 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,215 IT Pros & Developers. It's quick & easy.

How Referencing Superglobals?

P: n/a
Hi All,

<?php
$vars= array("_SERVER[HTTP_REFERER]","_SERVER[HTTP_USER_AGENT]","_SERVER[REMOTE_HOST]","_SERVER[REMOTE_ADDR]","_SERVER[QUERY_\
STRING]","_SERVER[PATH_INFO]");
foreach($vars as $var) {
if(isset($$var))echo("$var: ${$var}<br>\n");
}
?>

php.net:
Please note that variable variables cannot be used with PHP's
Superglobal arrays. This means you cannot do things like ${$_GET}. If
you are looking for a way to handle availability of superglobals and
the old HTTP_*_VARS, you might want to try referencing them.

Could someone hint me please how to use a reference here to get it or
is there a other error above?

Thank you in advance!
Regards, Jan
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
xcomm wrote:
Hi All,

<?php
$vars= array("_SERVER[HTTP_REFERER]","_SERVER[HTTP_USER_AGENT]","_SERVER[REMOTE_HOST]","_SERVER[REMOTE_ADDR]","_SERVER[QUERY_\
STRING]","_SERVER[PATH_INFO]");
foreach($vars as $var) {
if(isset($$var))echo("$var: ${$var}<br>\n");
}
?>

php.net:
Please note that variable variables cannot be used with PHP's
Superglobal arrays. This means you cannot do things like ${$_GET}. If
you are looking for a way to handle availability of superglobals and
the old HTTP_*_VARS, you might want to try referencing them.

Could someone hint me please how to use a reference here to get it or
is there a other error above?

Thank you in advance!
Regards, Jan


after looking at this until I am blind, I finally read the docs... Duhhh!!

<<http://us2.php.net/manual/en/language.variables.variable.php>>

Warning
Please note that variable variables cannot be used with PHP's
Superglobal arrays. This means you cannot do things like ${$_GET}. If
you are looking for a way to handle availability of superglobals and the
old HTTP_*_VARS, you might want to try referencing them.

So, in other words... you're out of luck... Since it is only 5 or 6 of
them and you have to get them into an array, just processes them without
putting them into an array -- as you have seen, can't be done...

Michael Austin.
Jul 17 '05 #2

P: n/a
xcomm wrote:
<?php
$vars= array("_SERVER[HTTP_REFERER]","_SERVER[HTTP_USER_AGENT]","_SERVER[REMOTE_HOST]","_SERVER[REMOTE_ADDR]","_SERVER[QUERY_\
STRING]","_SERVER[PATH_INFO]");
foreach($vars as $var) {
if(isset($$var))echo("$var: ${$var}<br>\n");
}
?> .... Could someone hint me please how to use a reference here to get it or
is there a other error above?


Try this:

<?php
$keys = array('HTTP_REFERER]', 'HTTP_USER_AGENT]', 'REMOTE_HOST',
'REMOTE_ADDR', 'QUERY_STRING', 'PATH_INFO');

foreach ($keys as $key) {
if (isset($_SERVER[$key])) echo "_SERVER[$key]: {$_SERVER[$key]}<br>\n";
else echo "_SERVER[$key] is not set<br>\n";
}
?>

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.