...

View Full Version : Help to modify referrer php script - see code



DJ Hands3
08-22-2011, 07:52 PM
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
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), 0, 21);
}
$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($result, MYSQL_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($result, MYSQL_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

//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), 0, 21);
}
$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($result, MYSQL_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($result, MYSQL_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

DJ Hands3
09-01-2011, 06:16 PM
Job now complete thanks for the replies :cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum