find current hostname in php

To find the current hostname in PHP, you can use the $_SERVER['HTTP_HOST'] variable. This variable contains the hostname from the current request headers.

Here's an example code snippet:

main.php
$currentHost = $_SERVER['HTTP_HOST'];
echo "Current hostname is: $currentHost";
80 chars
3 lines

This will output something like:

main.php
Current hostname is: example.com
33 chars
2 lines

Note that the $_SERVER variable is an array that contains various server and execution environment information, so be sure to sanitize and validate any user input that is derived from it.

gistlibby LogSnag