SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Belgium
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_SERVER['HTTP_REFERER'] question

    Hey guys.
    I want to make a box on my site, that shows the top referrers.
    So i thought doing this by using $_SERVER['HTTP_REFERER']
    Now what i want to do is, store evey referrer in the database, but if the referrer already exists, just update the "in" (hits in) column in the database with +1. So i don't have 300 times, the same site name in the table.
    Also, http://www.ee13.com , http://ee13.com (or any other possibilitys like subpages etc.) should be the same.
    Can someone help me with this ?
    I don't really know how to start ... (how to check if it doesn't exist already in the table and how to have the different types of urls be the same referrer ...)

    Thanks!

  2. #2
    SitePoint Enthusiast adriancid's Avatar
    Join Date
    Aug 2005
    Location
    Versalles, Santiago de Cuba, Cuba
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using in you SQL code, LIKE

  3. #3
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, well that's fairly simple. The same way user registration works: check if it already exists; if not, don't insert it. So create a database table with 2 fields, a text field and an auto_increment id field, the primary key.

    Then on index.php, first SELECT from the database to see if the referrer already exists. Then if so, just go on with the page. If not, insert it and go on with the page.

    As to not getting variations, I'm sure someone could write you a regular expression that would extract just the domain and TLD.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Belgium
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And how do i do this:
    "Also, http://www.ee13.com , http://ee13.com (or any other possibilitys like subpages etc.) should be the same."

    How to shorten the url ?
    Thanks!

  5. #5
    SitePoint Wizard lorenw's Avatar
    Join Date
    Feb 2005
    Location
    was rainy Oregon now sunny Florida
    Posts
    1,104
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Once you get the url you could try something like

    Code:
    $referer = str_replace('http://www.', '', $referer);
    $referer = str_replace('http://', '', $referer);
    // now you just have the domain and subpages
    //this is straight from php.net
    $pieces = explode("/", $referer);
    $domain = $pieces[0]; 
    // now you have domain being ee13.com and you can put it back together when you call it from the db
    anyway thats how I would do it

    HIH
    Loren

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Or with regex

    <?php
    $url = "http://www.mysite.com/subdir/index.php";
    preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $temp);
    $long = $temp[2];
    preg_match("/[^\.\/]+\.[^\.\/]+$/", $long, $final);
    echo 'long domain name is : ' . $long . '<br />';
    echo 'short domain name is : ' . $final[0] ;
    ?>
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  7. #7
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Belgium
    Posts
    387
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, ok that's kinda working so far.
    But how do i check if something doesn't already exist in the table ?
    Thanks!

    // edit:
    Also, i do not want it to check for referals within my site ...
    For example, the script shouldn't run, if the visitor comes from mydomain.com/index.php to mydomain.view.php
    It should only work for referals from other sites ...
    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •