This is odd, but for some reason the $_SERVER[\"SCRIPT_URI\"] will not return the domain name when I am in child/sub-pages but will only work on the main page.
$_SERVER[\"SCRIPT_URI\"]
var_dump($_SERVER) and see what suites your needs.
var_dump($_SERVER)
P.S. Making use of unsanitized $_SERVER["PHP_SELF"] could be a security risk.
$_SERVER["PHP_SELF"]