PHP Function Gethostname
Get the host name of the system where your PHP application is running. This can be useful for a variety of reasons including customizing output based on the environment your application is running in (development, testing, production), or for logging purposes.
php function gethostname returns the standard host name of the local machine, it doesn't take any parameters and return a string with the hostname on success and FALSE on failure. It was introduced in PHP 5.3 and replaces the older php_uname function.
In case you need to convert a hostname into an IP address, you can use gethostbyaddr function which takes an input as an argument and returns the list of IP addresses or FALSE if the lookup fails. This is a simple and straightforward way to resolve an IP address to a hostname in PHP.
You can also use gethostnamel() function to print the hostnames in a list or array. This function is very useful if you need to print multiple host names in your code and it is not hard to use.
If you're looking for more information on php, check out O'Reilly's extensive range of books, videos, and events. O'Reilly members experience books, live events, courses curated by job role, and more from nearly 200 top publishers. Start your free trial today. No credit card required. You can cancel anytime. It's safe, easy to use, and comes with a money-back guarantee. Click here for more details.