How to get host name, protocol and IP address in PHP _php tips

Source: Internet
Author: User
Tags get ip

This article is an example of how to obtain a host name, protocol, and IP address in PHP. Share to everyone for your reference.

The specific implementation code is as follows:

Copy Code code as follows:
$hostname =gethostbyaddr ($_server[' remote_addr ')); Get host Name
Echo $hostname; Output results
//
$hosts =gethostbynamel (' localhost '); Get IP Address List
Print_r ($hosts); Output array
//
$protocol = ' TCP '; Define Agreement name
$get _prot=getprotobyname ($protocol); Return Agreement Number
if ($get _prot==-1)//If not found
{
Echo ' Invalid protocol '; Output error message
}
Else
{
echo ' Protocol # '. $get _prot; Output the corresponding protocol number
}
//
$protocol _num= ' 6 '; Define Agreement Number
$get _prot=getprotobynumber ($protocol _num); Return Agreement name
if ($get _prot==-1)//If not found
{
Echo ' Invalid protocol '; Output error message
}
Else
{
echo ' Protocol # '. $get _prot; Output the appropriate protocol name
}

I hope this article will help you with your PHP program design.

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.