PHP how to get the base domain/url?
Shortest solution:
$domain = parse_url('http://google.com', PHP_URL_HOST);
Use SERVER_NAME
.
echo $_SERVER['SERVER_NAME']; //Outputs www.example.com
You could use PHP's parse_url()
function
function url($url) {
$result = parse_url($url);
return $result['scheme']."://".$result['host'];
}