View Full Version : breaking apart HTTP_REFERER

08-02-2007, 04:22 AM
I need three parts of information from the HTTP_REFERER.

1) Any sudomains, not including the http:// or a trailing period. This could be mail or even users.johnsmith

2) The domain, not including any folders, files, or trailing / For instance google.com

3) The page, not including any folders, get data, or anchors. For instance contactus.php

This is best done with regex i'm sure, but I am quite horrible at it. Assistance would be lovely. Thank you.

08-02-2007, 08:39 AM
parse_url() (http://www.php.net/parse_url) is your friend.

08-02-2007, 09:21 AM
You can also use PEAR Net_URL http://pear.php.net/manual/en/package.networking.net-url.php

08-02-2007, 10:24 AM
aha! I knew there was something like that that I had used before. Thank you very much!

08-03-2007, 12:04 AM
parse_url() does not seperate the subdomain from the domain. Can someone help with that?

08-03-2007, 01:40 AM
$bits=explode('.', $url['host']);

$subdomain = $bits[0];
echo $subdomain;