超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<gethostbyaddrgethostbynamel>
Last updated: Fri, 22 Jun 2007

gethostbyname

(PHP 3, PHP 4 , PHP 5)

gethostbyname --  Get the IP address corresponding to a given Internet host name

Description

string gethostbyname ( string hostname)

Returns the IP address of the Internet host specified by hostname or a string containing the unmodified hostname on failure.

例子 1. A simple gethostbyname() example

<?php
$ip
= gethostbyname('www.example.com');

echo
$ip;
?>

See also gethostbyaddr(), and gethostbynamel().




add a note add a note User Contributed Notes
gethostbyname
sjohnson at fuzzygroup dot com
17-Mar-2002 02:27
<?php

//script to see if host exists on Internet

//following up on the above point about host name
//checking and SQL timeouts, run this test script
//and see how long it takes for 2nd call to
//hostname check to fail
//NOTE -- not PHP's fault -- nature of DNS

//A known good dns name (my own)
$nametotest = "fuzzygroup.com";

//Call address test function
testipaddress($nametotest);

//A known bad name (trust me)
$nametotest = "providence.mascot.com";
//Call address test function
testipaddress($nametotest);

//ip address checking function
//for real use should have a return value but example code
function testipaddress ($nametotest) {
$ipaddress = $nametotest;
$ipaddress = gethostbyname($nametotest);
if ($ipaddress == $nametotest) {
echo "No ip address for host, so host "
    . "not currently available in DNS and "
    . "probably offline for some time
";
}
else {
echo "good hostname, ipaddress = $ipaddress
";
}
}

//Recommended fix for sql applications:
// store url to temporary table
// run second process periodically to
// check urls and update main table
?>

<gethostbyaddrgethostbynamel>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22