Method of Obtaining Host Name Protocol and IP Address in php
- 2021-08-05 09:15:25
- OfStack
This paper describes the method of obtaining host name, protocol and IP address in php. Share it for your reference.
The specific implementation code is as follows:
$hostname=gethostbyaddr($_SERVER['remote_addr']); // Get the host name
echo $hostname; // Output result
//
$hosts=gethostbynamel('localhost'); // Get ip Address list
print_r($hosts); // Output array
//
$protocol='tcp'; // Define a protocol name
$get_prot=getprotobyname($protocol); // Return agreement number
if($get_prot==-1) // If you can't find it
{
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); // Returns the protocol name
if($get_prot==-1) // If you can't find it
{
echo 'invalid protocol'; // Output error message
}
else
{
echo 'protocol #'.$get_prot; // Output the corresponding protocol name
}
I hope this article is helpful to everyone's php programming.