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.