
Sometimes you need to get the domain name from the page referring to your page... You don't need the whole url/path/page, just the domain... You also don't need/want to worry about the 'www.' at the beginning, that's if of course it's there.... just the domain name...
$justDomain = str_replace('www.','',parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
This will output something like jonmoore.co.uk
Main Category