All pastes #507567 Raw Edit

Something

public text v1 · immutable
·published 2007-05-24 17:09 UTC
rendered paste body
<?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.zambilici.ro') {
	
			$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 20"; // 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> ['.$row['hits'].']<br />';
}
?>