Forum Moderators: coopster
<?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.yoursite.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 />';
}
?>
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<a href="http://'.$row['website'].'">'.$row['website'].'</a> - <b>'.$row['hits'].'</b><br />';
}
you could use str_replace [php.net]
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$thesite = str_replace('www.','',$row['website']);
echo '<a href="http://'.$thesite.'">'.$thesite.'</a> - <b>'.$row['hits'].'</b><br />';
}
or just in the actual link text?
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<a href="http://'.$row['website'].'">'.str_replace('www.','',$row['website']).'</a> - <b>'.$row['hits'].'</b><br />';
}