473,665 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How Referencing Superglobals?

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
2 1677
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.variab les.variable.ph p>>

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
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_REF ERER]', 'HTTP_USER_AGEN T]', '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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2075
by: Dalibor Karlovic | last post by:
I need to access exaclty one of the superglobals arrays and don't want to use $_REQUEST. Having the name of the form method used on submit in $this->sMethod and the name of the feild submited in $sName, I've tried ${'$_'. strtoupper($this->sMethod)} but it doesn't work. Writting a form generation/validation class, that is why I need this. If somebody has an idea... I've found that accessing superglobals like this won't work (which is...
1
2280
by: student | last post by:
while compiling on: SunOS 5.8 Generic_108528-27 sun4u sparc SUNW,Sun-Fire-280R I get the following error: Undefined first referenced symbol in file matrixi_ tst.o ld: fatal: Symbol referencing errors. No output written to a.out
6
2461
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if the amount of records for a particular date is positive, i want the form to stop running, if there are no records that contain the date in question, then it should continue to run the form. The problem i'm having is referencing the date that is...
6
2470
by: Mikey_Doc | last post by:
Hi We are running cms 2002, Framework 1.0 with Visual studio 2002. We have just upgraded to Framework 1.1 and visual studio 2003. All of our database connection strings are stored within the machine config, this was necessary as our web site has 4 environments and the database server has a different name in each. Since the upgrade the applications can't read the strings in the
3
3853
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a hyperlink control and you assign the navigateurl property = "../#anchor" whereby you want to add this # reference to the current url the url ends up with the #anchor twice.
9
1590
by: Brett Romero | last post by:
Say I have a library (A.dll) with a method that accepts a collection of a specific type. The type is defined in B.dll. In A.dll, I need to loop through this collection and reference fields of the type. For example, a Person type. It may have arm, leg, feet, and hands. Hands is a collection containing types of fingers. The only way to get at fingers is by accepting the parameter as its true type. This means I'll need a file...
1
2364
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been installed into the GAC. We originally had this assembly without a strong-name and we were successfully using it by referencing it when it was NOT in the GAC. The assembly was built using the 1.0 framework and we were able to call it from both 1.0...
6
2612
by: chrispclay | last post by:
Hi, i am having problems with using superglobals. I have been trying to use the $_GET and $_POST superglobals but no matter which one i use, it doesn't print out anything. It doesn't print out what i am trying to reach from a form. Is it something to do with my php.ini file? I have read somewhere that it is something to do with the register_globals part but am still not sure. Is there something i should do to enable these superglobals? Any help...
2
1528
by: clai83 | last post by:
Hi everyone, I have a question regarding vulnerabilities related to PHP superglobals, in particular $_SERVER. I will have a website on a shared hosting environment, and I am unsure of the risks of using the variables such as $_SERVER for things such as "including" files i.e using the include, or require function. Are there any know methods to spoof these variables? I am doing my best to mitigate security risks; however, I do not...
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8779
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.