Monday, August 20, 2007

Top 10 Refferer

Here i will show how to log your refferers

create reff_connec.php write

//Connect to your rating database
$mysql_dbhost = 'localhost'; //your sql host
$mysql_dbuser = 'root'; //your sql username
$mysql_dbpass = 'pass'; //sql pass
$mysql_dbname = 'cdcol'; //database name

$rating_conn = mysql_connect($mysql_dbhost, $mysql_dbuser, $mysql_dbpass) or die ('Error connecting to mysql');
mysql_select_db($mysql_dbname);

close reff_connec.php

Now create refferer.php write the following

include('reff_connec.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];
//Is found
// 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);
$mysite=eregi('google',$site['website']); //chage googlet with your site name
if ($site['website'] != 'www.') {
if (!$mysite) {
$hits = $site['hits'] + 1;
$website = $site['website'];
$query = "UPDATE referers SET hits = $hits WHERE website = '$website'";
$result = mysql_query($query);
}
}

} else {

if (!empty($surl)&&!$mysite) {
$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 ''.$row['website'].' - '.$row['hits'].''; //replace all -- as its only given as to disable html in post.
}
Copyright Ayon Baidya

No comments:

Post a Comment