Web Analytics Made Easy -
StatCounter Problem with referrer list - CodingForum

Announcement

Collapse
No announcement yet.

Problem with referrer list

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with referrer list

    Hi I found a good referrer php snip here http://www.tutorialcode.com/php/top-referer-script/

    I am trying to modify it so I can block certain sites including mine being added to the list for obvious reasons, just external incoming sites I want entered to my database,

    I tried to create an array of sites such that I don't want added to my referrer list, except now the database just dosen't record anything heres what I have so far

    PHP Code:
    <?php

    //Connect to DB
    require('referrer_connect.php');

    // Find out referer and strip down to base domain.
    $ref parse_url($_SERVER['HTTP_REFERER']);

    //Block Your site from being added to the referrer's list
    $noreferrer=array('www.mysite.com');
    if(isset(
    $_SERVER['HTTP_REFERER']) && in_array($_SERVER['HTTP_REFERER'],$noreferrer))
     
    $ref '';
    else
    // Split our URL into bits.
    $url explode("/",$ref);
    // Take the 3rd part of the url (the main site)
    $surl $url[2];
    // Check to see if it contains the www. at the begining
    $found ereg('\www.',$surl);
    if (
    $found) {
      
    $url $surl;
    } else {
      
    $url 'www.'.$surl;
    }
    $query "SELECT website, hits FROM referers WHERE website = '$url'";
    $result mysql_query($query);
    $num mysql_num_rows($result);
    if (
    $num == 1) {
      
    $site mysql_fetch_array($resultMYSQL_ASSOC);
      if (
    $site['website'] != 'www.') {
        if (
    $site['website'] != 'www.tutorialcode.com') {
          
    $hits $site['hits'] + 1;
          
    $website $site['website'];
          
    $query "UPDATE referers SET hits = $hits WHERE website = '$website'";
          
    $result mysql_query($query);
        }
      }
    } else {
      if (!empty(
    $surl)) {
        
    $query "INSERT INTO referers (website, hits) VALUES ('$url', '1')";
        
    $result mysql_query($query);
      }
    }
    $query "SELECT * FROM referers ORDER BY hits DESC LIMIT 10"// Change the limit to the top XX that you want to show.
    $result mysql_query($query);
    while (
    $row mysql_fetch_array($resultMYSQL_ASSOC)) {
      echo 
    '<img src="images/top_star.png" alt="" title="top_star" width="16" height="16" border="0" /> <a href="http://'.$row['website'].'">'.$row['website'].'</a> - <b>'.$row['hits'].'</b><br />';
    }
    ?>

  • #2
    Well to start I think you need an opening curly bracket just before the comment "// Split our URL into bits. "

    Comment

    Working...
    X
    😀
    🥰
    🤢
    😎
    😡
    👍
    👎