About
Kooty's TechnoBabble is a blog by Brennan Kootnekoff, and is about the interesting day-to-day life of a multi-platform systems engineer/administrator. From time to time, he will post useful tidbits of information here that may save hours of time, and prevent premature gray hairs and aging.
Search
Categories
Other
FortiScan Certified
April 19th, 2008. comments are open 3 commentsTwo PHP Snippets for URL Parsing

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