PHP obtains the Host Name and domain name functions.

Source: Internet
Author: User
Today we see several functions that can be used to obtain the corresponding domain name ip address based on the ip address domain name. This is recorded. Gethostbynamel ($ hostname) obtains the IP address based on the domain name and returns an array, such as baidu. Returns two ip addresses indicating arraygethostbynamel (string $ hostname) ReturnsalistofIPv4a

Today we can see several functions that can be used to obtain the corresponding domain name/ip address based on the ip address/domain name. This is recorded. Gethostbynamel ($ hostname) // obtain the IP address based on the domain name and return an array, such as baidu. Returns two ip addresses indicating array gethostbynamel (string $ hostname) Returns a list of IPv4

Today we can see several functions that can be used to obtain the corresponding domain name/ip address based on the ip address/domain name. This is recorded.

Gethostbynamel ($ hostname) // AccordingDomain NameObtainIP, return an array, such as baidu. Com, two ip addresses are returned.

Description: array gethostbynamel (string $ hostname) Returns a list of IPv4 addresses to which the Internet host specified by hostname resolves. parameter hostname The host name. returned Returns an array of IPv4 addresses or FALSE if hostname cocould not be resolved.

Gethostbyname ($ hostname)// AccordingDomain NameObtainOnly the first IP address is returned.

Gethostbyname-Get the IPv4 address corresponding to a given Internet host name Description string gethostbyname (string $ hostname) Returns the IPv4 address of the Internet host specified by hostname. parameter hostname The host name. return Value Returns the IPv4 address or a string containing the unmodified hostname on failure.

Gethostbyaddr ($ ip) // obtain the domain name based on the IP address

Gethostbyaddr-Get the Internet host name corresponding to a given IP address description string gethostbyaddr (string $ ip_address) Returns the host name of the Internet host specified by ip_address. parameter ip_address The host IP address. return Value Returns the host name on success, the unmodified ip_address on failure, or FALSE on malformed input.

Example:

$hostname = 'www.baidu.com';$addr = '127.0.0.1';print_r(gethostbyname($hostname));echo '
';print_r(gethostbyaddr($addr));echo '
';print_r(gethostbynamel($hostname));

Output

220.181.111.148idc-wangArray ( [0] => 220.181.111.148 [1] => 220.181.112.143 ) 

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.