★ wanayoo — archive 1999 http://www.php.net/manual/it/function.getenv.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to PHP options/info
Quick Reference
English version of this pageGerman version of this pageJapanese version of this pageFrench version of this pageHungarian version of this page
PHP options/info
* error_log
* error_reporting
* extension_loaded
* getenv
* get_cfg_var
* get_current_user
* get_magic_quotes_gpc
* get_magic_quotes_runtime
* getlastmod
* getmyinode
* getmypid
* getmyuid
* getrusage
* phpinfo
* phpversion
* php_logo_guid
* php_sapi_name
* putenv
* set_magic_quotes_runtime
* set_time_limit
* zend_logo_guid
* get_loaded_extensions
* get_extension_funcs
* get_required_files
* get_included_files
Manual: getenv
View the source code for this pageSearch the site



Previous page
 extension_loaded
 Updated
Sun, 06 Aug 2000
get_cfg_var 
Next page


getenv

(PHP3 , PHP4 )

getenv -- Get the value of an environment variable

Description

string getenv (string varname)

Returns the value of the environment variable varname, or false on an error.


$ip = getenv("REMOTE_ADDR"); // get the ip number of the user 
      

You can see a list of all the environmental variables by using phpinfo(). You can find out what many of them mean by taking a look at the CGI specification, specifically the page on environmental variables.


User Contributed Notes: getenv


sorry@spammed.nut
12-Jul-1999 07:43
To show a use of getenv("QUERY_STRING")....

suppose you have a site with frames... the frames create the "interface", and one frame called "main" has an active document... now, suppose you made a page.php3 which took an argument "pg" and spit out the framesets necessary, with "main" frame containing whatever "pg" is... so now you can bring up any page in your site with page.php3?pg=test.html
now, take this one step further, and suppose you want outside links to point to php3 pages which takes parameters, ON your site... but you still want them to appear in frames, so what do you do? well, if "ok.php3" was the page you wanted to show, and it was requested as "ok.php3?some=params&go=here", then the very thing in the beginning of ok.php3 could be <pre>if (!isset($inframe)) {
header("Location: http://yoursite/page.php3?pg=".urlencode("inframes=1&").getenv("QUERY_STRING"));
exit;
}</pre>
Now... you might ask, how in the world did I come up with THAT? Well, perhaps it was because I came here not able to remember which environment variable held the query string...



timeblind@crucial-systems.com
12-Feb-2000 09:55
This is a touch buried in the docs. If you need to iterate over form submitted fields (and you don't always know what they are going to be):

If PHP's track_vars feature is turned on, either by the track_vars configuration setting or the <?php_track_vars?> directive, then variables submitted via the POST or
GET methods will also be found in the global associative arrays $HTTP_POST_VARS and $HTTP_GET_VARS as appropriate.



c.k.karssen@student.tudelft.nl
22-May-2000 09:52
Get the RIGHT IP adress of the current user

When you use REMOTE_ADDR for getting the IP of the current user,
sometimes you get the IP of the ISP Cache server.
When this happens, the HTTP_X_FORWARDED_FOR is also set, it
contains the IP of the user.

So with this script, you always get the right IP:

<PRE>
if (getenv(HTTP_X_FORWARDED_FOR)){
$ip=getenv(HTTP_X_FORWARDED_FOR);
}
else {
$ip=getenv(REMOTE_ADDR);
}
</PRE>

For comments please mail me.
Klemens Karssen



john-php@pc.xs4all.nl
15-Aug-2000 06:56
Note that the X-Forwarded for header might contain multiple addresses, comma separated, if the request was forwarded through multiple proxies.

Finally, note that any user can add an X-Forwarded-For header themselves. The header is only good for traceback information, never for authentication. If you use it for traceback, just log the entire X-Forwarded-For header, along with the REMOTE_ADDR.



 About Notes


Previous page
 extension_loaded
 Updated
Sun, 06 Aug 2000
get_cfg_var 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.