note 69205 added to function.gethostbyname
| From: | zmorris at zsculpt dot com | Date: | Sun, 27 Aug 2006 02:05:21 +0000 |
| Subject: | note 69205 added to function.gethostbyname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116377@lists.php.net to get a copy of this message | ||
If you need something like getifaddrs() or gethostid() to get the machine's main IP address,
you can try $_SERVER['SERVER_ADDR'] but that often returns 127.0.0.1. This happens a lot
if you are just testing at home on a vanilla machine. Instead, try this:
gethostbyname( $_SERVER['SERVER_NAME'] )
It will usually return the correct IP address, something like 192.168.0.50 if you are on LAN. I
have only tested machines behind NAT, but it should work on a machine connected directly to the
internet. Perhaps check if $_SERVER['SERVER_ADDR'] is 127.0.0.1 and if so, fall back to
the above method.
----
Server IP: 66.163.161.117
Probable Submitter: 71.221.143.57
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.gethostbyname.php
Edit -- https://master.php.net/note/edit/69205
Del: integrated -- https://master.php.net/note/delete/69205/integrated
Del: useless -- https://master.php.net/note/delete/69205/useless
Del: bad code -- https://master.php.net/note/delete/69205/bad+code
Del: spam -- https://master.php.net/note/delete/69205/spam
Del: non-english -- https://master.php.net/note/delete/69205/non-english
Del: in docs -- https://master.php.net/note/delete/69205/in+docs
Del: other reasons-- https://master.php.net/note/delete/69205
Reject -- https://master.php.net/note/reject/69205
Search -- https://master.php.net/manage/user-notes.php