How To Use PHP Network Functions In Example
Hi guys,
Today i will explained how to use php Network functions. This example is so easy to use in php.
This functions is provided to the default php language. So you can easily to use in your php code. Today i will explaind gethostbyaddr(),gethostbyname(),gethostbynamel(),gethostname(),getmxrr() to explainded.
So let's start to the example.
gethostbyaddr() Function
gethostbyaddr() function returns the domain name for a given IP address.
<?php
$host = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
echo $host;
?>
Output
localhost
gethostbyname() Function gethostbyname() function returns the IPv4 address for a given domain/host name.
<?php
$ip = gethostbyname("www.w3schools.com");
echo $ip;
?>
Output
192.229.133.221
gethostbynamel() Function
The gethostbynamel() function returns a list of IPv4 address for a given domain/host name.
<?php
$hostlist = gethostbynamel("www.w3schools.com");
print_r($hostlist);
?>
Output
Array
(
[0] => 192.229.133.221
)
gethostname() Function
The gethostname() function returns the host name for the local machine.
<?php
echo gethostname();
?>
Output
A
getmxrr() Function getmxrr() function returns the MX records in the specified internet host name.
<?php
$domain="w3schools.com";
if(getmxrr($domain,$mx_details)){
foreach($mx_details as $key=>$value){
echo "$key => $value <br>";
}
}
?>
Output
0 => aspmx.l.google.com
1 => alt3.aspmx.l.google.com
2 => alt4.aspmx.l.google.com
3 => feedback-smtp.eu-west-1.amazonses.com
4 => alt1.aspmx.l.google.com
5 => alt2.aspmx.l.google.com
Now you can check your own.
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example