tags:

views:

70

answers:

6

I was actually going through the question 1636644 .. and got confused with this

" The getenv() function access to any environment variable to get the related value! "

Also ..

" It would probably be better to use $_SERVER['REMOTE_ADDR']; to prevent incompatibilities between servers. "

what kind of compatibility issue can this be ??

Lastly, it says $_SERVER is an array with many elements but I find only the IP Address there .. does this array store anything else too???

apologies for all these questions packed in one .. this is bcoz these are all related ..

+3  A: 

The function 'getenv' does not work if your Server API is ASAPI (IIS).

(source)

Also, see this link for what may be contained within the $_SERVER variable.

Jon Grant
A: 

I think those incompatibilities would be because of the different ways that web server manage their environment variables.

The $_SERVER variable manages these differences by itself.

Answering your last question, you can access the variables of the $_SERVER array this way:

$_SERVER['SCRIPT_NAME']
$_SERVER['REQUEST_URI']

and so on... you can see the reference here: http://www.php.net/manual/en/reserved.variables.server.php

David
A: 

$_SERVER may contain a lot of information; you could be interested in:

  • HTTP_CLIENT_IP
  • HTTP_FORWARDED
  • HTTP_X_FORWARDED_FOR
  • REMOTE_ADDR
toscho
A: 

Create a php page containing the following to see the contents of $_SERVER along with a host of other useful information about your server.

<?php phpinfo(); ?>
drawnonward
+1  A: 

To see what all $_SERVER contains, just do:

echo "<pre>";
print_r($_SERVER);
echo "</pre>";

The pre tag just makes the output presentable in the browser.

To see ALL of the environmental variables that the server is setting (and tons more), make a script that just has:

<?php

phpinfo();

?>

It will be listed toward the bottom, as PHP Variables.

The differences in environment variables can be based on the HTTP server (apache vs IIS) and other factors, such as if the page is served over SSL.

Anthony
thanks a lot.. i guess this is what i had been in search of ..
Sachindra
A: 

$_SERVER['ROMOTE_ADDR'],ROMOTE_ADDR,getHostByName() using this 3 ways u can find ip address

sam