<?php
$domain = $_SERVER['HTTP_HOST'];
echo $domain; // Outputs: example.com (or example.com:8080)