gethostname()

gethostname() — Gets the host name.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.3.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

gethostname() gets the standard host name for the local machine.

Signature

gethostname(): string|false

Parameters

This function takes no parameters.

Return value

Returns a string with the hostname on success, otherwise false is returned.

Example

A runnable snippet:

echo gethostname(); // may output e.g,: sandie

See also

gethostbyname(), gethostbyaddr(), php_uname()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page gethostname() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.