Hello, i got a code from http://www.tutorialcode.com/php/top-referer-script/ i tried many times to modify it to my needs with no success
first the code
<?php
require('mysql_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;
}
$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 '<a href="http://'.$row['website'].'">'.$row['website'].'</a> - <b>'.$row['hits'].'</b><br />';
}
?>
what i need is the following:
instead of displaying just the www.example.com referer info i want www.example.com/subfolder also if the referer is www.example.com/subfolder/subfolder i want it to display as www.example.com/subfolder.
also is it possible for the script to record a hit, the referrer url must already exist on the database, or else it will get ignored, which brings me to the next point, add a referer manually using a text field.
and last but not least, how can i get unique hits?
any help is greatly appreciated, is it too hard? will i have to pay for it?
thank you!
Phil