Page 1 of 1

HTTP REFERRALS

Posted: Tue Aug 05, 2003 1:18 pm
by lloydsmods
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.

Posted: Tue Aug 05, 2003 1:49 pm
by Kriek
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;
?>

Excellent

Posted: Tue Aug 05, 2003 2:14 pm
by lloydsmods
Worked like a charm. I never cease to be amazed at how quickly you can find quality info in this forum.

Thanks a million!

Posted: Tue Aug 05, 2003 5:24 pm
by Kriek
No problem, glad I could be of assistance to you ;)