Okay, I'm using $_SERVER['HTTP_REFERER'] to track down where my visitors are coming from. I'm posting the results to a MySQL database, as well. Question is this: How do I trim the URL down so that I only capture the site or the site and page without all the extra garbage?
For example, I get this kind of stuff:
http://www.google.com/search?hl=en&lr=& ... ts&spell=1
Suppose I just want to trim off everything after google.com? I know there is a way to do this but I haven't had much luck.
HTTP REFERRALS
Moderator: General Moderators
Sure using parse_url()
Code: Select all
<?php
$referral = $_SERVER['HTTP_REFERER'];
if (isset($referral)) {
$pieces = parse_url($referral);
$referer = $pieces[host];
$pagereferer = $pieces[path];
} else {
$referer = 'unknown';
}
echo 'http://' . $referer . $pagereferer;
?>-
lloydsmods
- Forum Newbie
- Posts: 22
- Joined: Wed Aug 14, 2002 2:03 pm
- Location: NC
Excellent
Worked like a charm. I never cease to be amazed at how quickly you can find quality info in this forum.
Thanks a million!
Thanks a million!