We now have a youtube channel. Subscribe!

PHP | gethostname() Function

PHP gethostname() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP gethostname() Function.

The built-in PHP gethostname() function is used to get the host or domain name for the local machine.


Following below is the syntax to use this function -

string gethostname ( void )

Parameter Details

This built-in PHP function doesn't accept any parameters.

Return Value

This PHP function returns a string value of host name on success, otherwise FALSE on failure.


Try out the following example below -

   $var = gethostname();
   IF ($var===FALSE) {
      echo "The function ran but no results were returned!";
   } ELSE {
      echo "The function returned a value ";
      echo $var;


When the above code is executed, it will produce the following result below -

The function returned a value 4d623edc62d4

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will study about the PHP getmxrr() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain