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

    Help to modify referrer php script - see code

    1) Project Details: (be as specific as possible):

    I have a referral script in PHP that lists the incoming sites to my website.

    The script works, but needs modifying so it dosen't record my website www.djhandsfree.co.uk as it dose at the moment, also the referral url must trimed so it dosen't go over 21 characters as this messes up my layout and only want the url to be on 1 line

    2) Payment method/ details (Paypal, check? Timeline?):

    Payment will be sent upon completion via paypal, timeline on project is not critical

    Additional Info:


    Original script from http://www.tutorialcode.com/php/top-referer-script/

    Original PHP - Working but lists my site when I don't want it to:
    PHP Code:
    <?php
    require('referrer_connect.php');
    // Find out or base pure referer.
    $ref $_SERVER['HTTP_REFERER'];
    // 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;
      
    $limiturl substr(trim($url), 021);
    }
    $query "SELECT website, hits FROM referers WHERE website = '$limiturl'";
    $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> <img src="images/link-icon.png" alt="" title="link-icon" width="16" height="16" border="0" /><br />';
    }
    ?>
    My modified version - not working but no errors

    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('http://www.djhandsfree.co.uk');
    if(isset(
    $_SERVER['HTTP_REFERER']) && in_array($_SERVER['HTTP_REFERER'],$noreferrer))
    unset(
    $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;
      
    //Trim url down to keep 1 referrer per line
      
    $url substr(trim($url), 021);
    }
    $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> <img src="images/link-icon.png" alt="" title="link-icon" width="16" height="16" border="0" /><br />';
    }
    ?>
    My website to view the referrers list (bottom left column) www.djhandsfree.co.uk

    Please make an offer/quote,

    Thanks

  • #2
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Job now complete thanks for the replies


  •  

    Posting Permissions

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