How to obtain the host name, protocol, and IP address in php

Source: Internet
Author: User
This article describes how to obtain the host name, protocol, and IP address in php, including functions such as gethostbyaddr, gethostbynamel, getprotobyname, and getprotobynumber, and how to apply the $ _ SERVER variable.

This article describes how to obtain the host name, protocol, and IP address in php, including functions such as gethostbyaddr, gethostbynamel, getprotobyname, and getprotobynumber, and how to apply the $ _ SERVER variable.

This example describes how to obtain the host name, protocol, and IP address in php. Share it with you for your reference.

The specific implementation code is as follows:

The Code is as follows:

$ Hostname = gethostbyaddr ($ _ SERVER ['remote _ addr ']); // obtain the Host Name
Echo $ hostname; // output result
//
$ Hosts = gethostbynamel ('localhost'); // obtain the IP address list
Print_r ($ hosts); // output Array
//
$ Protocol = 'tcp '; // define the protocol name
$ Get_prot = getprotobyname ($ protocol); // return the protocol Number.
If ($ get_prot =-1) // if not found
{
Echo 'invalidprotocol'; // output error message
}
Else
{
Echo 'Protocol # '. $ get_prot; // output the corresponding protocol number
}
//
$ Protocol_num = '6'; // defines the Protocol Number.
$ Get_prot = getprotobynumber ($ protocol_num); // return the protocol name.
If ($ get_prot =-1) // if not found
{
Echo 'invalidprotocol'; // output error message
}
Else
{
Echo 'Protocol # '. $ get_prot; // output the corresponding protocol name
}

I hope this article will help you with php programming.

,

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.