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.
,