Таблица: CREATE TABLE `referer` ( |
url varchar(100) NOT NULL, |
hits int(10) DEFAULT '0' NOT NULL, |
PRIMARY KEY (url) |
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
файл который необходимо инклюдить в нужные страницы: |
<?php |
$hostname1 = ""; |
$username1 = ""; |
$password1 = ""; |
$userstable1 = "referer"; |
$dbName1 = ""; |
$ref = strtolower($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"; |
$query1 = "insert into $userstable1 (url,hits) values ('$ref','$hits')"; |
else { |
$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); |
} } |
?> |
файл вывода информации: |
<?php |
|
$hostname1 = ""; |
$username1= ""; |
$password1 = ""; |
$userstable1 = "referer"; |
$dbName1 = ""; |
|
$color10 = "#FFFF00"; |
$color20 = "#FF0000"; |
$color50 = "#008000"; |
$color1k = "#0000FF"; |
$color2k = "#0000A0"; |
$color5k = "#000040"; |
|
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 "<div 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>"; |
} |
} |
?> |