I recently was coding in PHP, and needed to get just the fully qualified domain name from the (FQDN) $_SERVER[’HTTP_REFERER’] variable. So I whipped a quick function up that may help some of you beginners out there looking to parse a URL:
function domainviaurl($url){
$parsed_url=parse_url($url);
$fqdn = $parsed_url['host'];
return $fqdn;
}
This will just spit out the domain name. The next one will take it one step further, and actually get the IP address of the referrer via the domain name.
function ipviaurl($url{
$parsed_url=parse_url($url);
$tld = $parsed_url['host'];
$ip = gethostbyname($tld);
return $ip;
}
Hope this helps out!
Brennan