referer.php
<?php
$hostname1 = ".mchost.ru";
$username1 = "_12";
$password1 = "Test12345";
$userstable1 = "referer";
$dbName1 = "_12";
$ref = strtolower($_SERVER['HTTP_REFERER']);
if(!empty($ref)) {
mysql_connect($hostname1,$username1, $password1) or die (mysql_error());
mysql_select_db("$dbName1") or die(mysql_error());
$query = "select * from $userstable1 where url = '$ref'";
$result = mysql_query($query);$rows = mysql_num_rows ($result);
if ($rows == 0){
$hits = "1";
$query = "insert into $userstable1 (url,hits) values ('$ref','$hits')";
$hitquery = "select hits from $userstable1 where url = '$ref'";
$result2 = mysql_query($hitquery);
$row = mysql_fetch_array($result2);
$hits = $row["hits"];
$query2 = "update $userstable1 set hits = hits+1 where url = '$ref'";
mysql_query($query2);
} }
?>
viewreferer.php
<?php
$hostname1 = ".mchost.ru";
$username1 = "_12";
$password1 = "Test12345";
$userstable1 = "referer";
$dbName1 = "_12";
$color10 = "#FFFF00";
$color20 = "#FF0000";
$color50 = "#008000";
$color1k = "#0000FF";
$color2k = "#0000A0";
$color5k = "#000040";
<head>
<title>test</title>
</head><body>
mysql_connect($hostname1, $username1,$password1) or die (mysql_error());
mysql_select_db("$dbName1") or die(mysql_error());
$query = "select * from $userstable1 order by hits desc";
$result = mysql_query($query);
$number = mysql_num_rows($result) or die (mysql_error ());
$i = 0;
if ($number == 0) {
echo '<center><p><b>Сведений о рефералах не обнаружено!</b></center>';
}
elseif ($number >= 1) {
while ($i < $number){
$row = mysql_fetch_array($result);
$hits = $row["hits"];
$ref = $row["url"];
if ($hits <10){
$color = "$color10";
} elseif (($hits >= 10 ) and ($hits < 20)){
$color = "$color20";
} elseif (($hits >= 20 ) and ($hits < 50)){
$color = "$color50";
} elseif (($hits >= 50 ) and ($hits < 100)){
$color = "$color1k";
} elseif (($hits >= 100 ) and ($hits < 200)){
$color = "$color2k";
} elseif ($hits >= 200){
$color = "$color5k";
}
echo "<td align="left">";
echo "<table cols="3" border="0" width="100%"><tr><td align="left" width="400"><b><a href="$ref">$ref</a></b></td>";
echo "<td align="right" width="60"><b>$hits</b></td>";
echo "<td align="left" width="$hits" bgcolor="$color"></td></tr>";
$i++;
}
}
echo"</table>";
echo "</body></html>";
?>