This is probably quite hard to explain, so I’ll try to make it as simple as possible:
Here’s my code:
<?php
$ref = $_SERVER['HTTP_REFERER'];
switch($ref) {
case "http://www.facebook.com":
$ref_name = "Facebook";
break;
case "http://www.twitter.com":
$ref_name = "Twitter";
break;
}
?>
From what I know, HTTP_REFERER pulls the entire referrer url (e.g. www.facebook.com/abc/xyz/mno=prq) as oppose to the top-level domain. I’d like to be able to match $ref against something so that all referrer’s whether from say http://static.facebook.com (a sub-domain) or http://www.facebook.com/profile_id/bla (a url with additional folders and parameters after the top-level domain) are given the value of "http://www.facebook.com".
What’s the most simple and effective way to do so?
Any comments/answers etc will be greatly appreciated :)!!
See: parse_url
Update: Have a look at Root Zone Database if you’re dealing with special TLDs.