note 78965 added to function.gethostbyname
| From: | Jonathon dot Reinhart at gmail dot com | Date: | Mon, 05 Nov 2007 03:31:27 +0000 |
| Subject: | note 78965 added to function.gethostbyname | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132004@lists.php.net to get a copy of this message | ||
In response to Peter <toomuchphp-phpman at yahoo dot com>
$myIP = gethostbyname(trim(
hostname));
In my situation this did not work. My server is sitting behind a NAT router, so it's IP address
was 192.168.1.10. So when I called your method, it returned 192.168.1.10, and never actually did
the lookup. To resolve this, I wrote this little function:
<?php
function look_me_up()
{
$records = dns_get_record( trim(hostname --fqdn) );
foreach($records as $record)
{
if ($record['type'] == 'A')
$ip = $record['ip'];
}
return $ip;
}
?>
Also note the use of --fqdn. hostname in my case only returned 'hostname'
instead of it's fully qualified domain name hostname.example.com.
----
Server IP: 216.92.131.65
Probable Submitter: 64.93.136.120
----
Manual Page -- http://www.php.net/manual/en/function.gethostbyname.php
Edit -- https://master.php.net/note/edit/78965
Del: integrated -- https://master.php.net/note/delete/78965/integrated
Del: useless -- https://master.php.net/note/delete/78965/useless
Del: bad code -- https://master.php.net/note/delete/78965/bad+code
Del: spam -- https://master.php.net/note/delete/78965/spam
Del: non-english -- https://master.php.net/note/delete/78965/non-english
Del: in docs -- https://master.php.net/note/delete/78965/in+docs
Del: other reasons-- https://master.php.net/note/delete/78965
Reject -- https://master.php.net/note/reject/78965
Search -- https://master.php.net/manage/user-notes.php