How PHP Gets the domain name IP address code function

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags address code domain domain name echo function get host

PHP tutorial How to get Domain name IP address code function

$DM = ' www.jzread.com ';
$ip = gethostbyname ($DM);
echo gethostbyaddr ($IP);
echo $ip;//Two output results are the same,
/*
About gethostbyname syntax

String gethostbyname (String $hostname)

Returns the IPv4 address of the Internet host specified by the host name
Returns the IPv4 address of the Internet host specified by hostname


Here's an example of this is the best way I've proposed to address any host name to the IP address when it's fast, reliable, and has timed out support! An invalid address, such as a Unicode string, returns 4? seconds, not 8 calls to gethostbyname?! It can only be with Unix though.
*/

function Getaddrbyhost ($host, $timeout = 3) {
$query = ' nslookup-timeout= $timeout-retry=1 $host ';
if (Preg_match ('/naddress: (. *) n ', $query, $matches))
return Trim ($matches [1]);
return $host;
}/*
GETHOSTBYADDR is to get the Internet host name for a specific IP address

String gethostbyaddr (String $ip _address) */

$hostname = gethostbyaddr ($_server[' remote_addr '));

Echo $hostname;
Original website Reprint www.jzread.com

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.