开发者

different ways of getting the IP Address

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 ele开发者_JAVA百科ments 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 ..


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.


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.


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

  • HTTP_CLIENT_IP
  • HTTP_FORWARDED
  • HTTP_X_FORWARDED_FOR
  • REMOTE_ADDR


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


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(); ?>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜