Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    May 2007
    Posts
    100
    Thanks
    16
    Thanked 11 Times in 11 Posts
    Well to start I think you need an opening curly bracket just before the comment "// Split our URL into bits. "


  •  

    Posting Permissions

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