反向链接(Referrers)系统可以很好的显示反向链接,目前很多站点上显示的最新来源(referer)统计都是用的是Stephen的referrer统计系统,比如 Booso 反向链接(Referrers)统计系统,还有一个朱传伟的反向链接统计服务不知道是不是他自己实现的。
总之,网上提供这些反向链接(Referrers)系统不是服务不好,就是定制性不好,所以,干脆,我烦了,自己花一天时间写了一个,并且公开源代码,基本上架构和功能都用了,但是还需要完善。
由于我没有支持 ASP + Access 的主机,所以无法为大家提供服务,希望有哪个同仁可以提供这个服务?或者 CSDN 会提供这个服务给我?效果图如下:
基本架构:
采用 ASP + Access
用下列脚本在需要统计的页面增加反向链接记录
<script language=javascript src="/lib/refadd.js"></script>
用下列脚本在需要显示的页面增加反向链接显示
<script language=javascript src="/lib/refcnt.js"></script>
数据库:
数据库只需要一张表即可
ID:整数
IP:字符串(255)
Agent:字符串(255)
To:字符串(255)
Name:字符串(255)
From:字符串(255)
Date:日期时间
其中"Name"字段的值是对 From 处理后的结果,比如 From="http://www.google.com/" 则Name="Google"
分析:
只需要简单一个 SQL 查询即可:
SELECT [NAME],COUNT(*) FROM [REFERRER] GROUP BY [NAME] ORDER BY COUNT(*) DESC"
如果需要,还可以加上必要的条件,比如显示访问次数大于3次的记录:
SELECT [NAME],COUNT(*) FROM [REFERRER] GROUP BY [NAME] HAVING COUNT(*)>3 ORDER BY COUNT(*) DESC"
基本功能:
反向链接记录
反向链接显示(支持多种参数)
文件列表:
lib/refadd.asp
lib/refadd.js
lib/refcnt.asp
lib/refcnt.js
lib/refcon.asp
lib/images/percent.gif
dat/refdb.mdb
源代码:
由于 CSDN 不提供文件下载功能,所以我还要找一个地方上传源代码,不知道哪里有,各位同仁请告知道
default.asp
<html>
<head>
<title>Top 100 Refering Sites</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<script language=javascript src="/lib/refadd.js"></script>
<script language=javascript src="/lib/refcnt.js"></script>
</body>
</html>
refadd.asp
<%@language=javascript%>
<!--#include file="refcon.asp" -->
<%
function makeURL(sName,sURL)
{
if(sURL.indexOf("http://") == 0)
{
sURL = sURL.substring(7);
}
return "<a href=\\\"http://" + sURL + "\\\">" + sName+ "</a>";
}
function getName(sIP, sURL)
{
var sName = sURL.toLowerCase();
if(sName == "")
{
sName = makeURL("Direct Refrence", sIP);
}
else
{
if(sName.indexOf("http://") == 0)
{
sName = sName.substring(7);
}
if(sName.indexOf("www.") == 0)
{
sName = sName.substring(4);
}
var nIndex = sName.indexOf("/");
if(nIndex > 0)
{
sName = sName.substring(0, nIndex);
}
if(sName.indexOf(".") == 0)
{
sName = makeURL("Not Avalible", sURL);
}
else
{
if(sName.indexOf("google") == 0)
{
sName = makeURL("Google", sURL);
}
else
if(sName.indexOf("yahoo") == 0)
{
sName = makeURL("Yahoo", sURL);
}
else
{
sName = makeURL(sURL, sURL);
}
}
}
return sName.substring(0,255);
}
var nCT = parseInt("" + Request.QueryString("ct")); if(isNaN(nCT)) nCT = 8;
var sIP = "" + Request.ServerVariables("REMOTE_ADDR"); if(sIP == "undefined" || sIP == "null") sIP = "";
var SQL = "SELECT [ID] FROM [REFERRER] WHERE [IP]='" + sIP + "' AND DATEDIFF('h',[DATE],NOW())<" + nCT;
var oRS = oConnect.Execute(SQL)
if(oRS.EOF && oRS.BOF)
{
var sRF = "" + Request.QueryString("fr");if(sRF == "undefined" || sRF == "null") sRF = "";
var sTO = "" + Request.QueryString("to");if(sTO == "undefined" || sTO == "null") sTO = "";
var sAG = "" + Request.ServerVariables("HTTP_USER_AGENT");
sRF = sRF.substring(0,255);
sTO = sTO.substring(0,255);
sAG = sAG.substring(0,255);
SQL = "INSERT INTO [REFERRER]([DATE],[IP],[NAME],[FROM],[TO],[AGENT])VALUES("
+ "NOW()"
+ ",'" + sIP + "'"
+ ",'" + SQLSTR(getName(sIP,sRF)) + "'"
+ ",'" + SQLSTR(sRF) + "'"
+ ",'" + SQLSTR(sTO) + "'"
+ ",'" + SQLSTR(sAG) + "'"
+ ")";
oConnect.Execute(SQL);
}
oRS.Close();oRS = null;
oConnect.Close();oConnect = null;
%>
refadd.js
function __refadd()
{
document.write("<sc");
document.write("ript language=javascript src='/lib/refadd.asp?ct=8&fr=" + document.referrer + "&to=" + document.location + "'>");
document.write("</sc");
document.write("ript>");
}
__refadd();
refcnt.asp
<%@language=javascript%>
<!--#include file="refcon.asp" -->
document.write("<table width=\"100%\"><tr><td width=\"100%\" align=center valign=top height=520><font size=\"+2\"><strong>");
<%
var sTO = "" + Request.QueryString("to"); if(sTO == "undefined" || sTO == "null") sTO = ""; else sTO = sTO.substring(0,255);
var SQL;
var oRS;
var sPR = " WHERE [TO]='" + SQLSTR(sTO) + "'";
var sST = "" + Request.QueryString("st"); if(sST == "undefined" || sST == "null") sST = "";
if(sST != "")
{
sPR += " AND [DATE]>=#" + sST + "#";
var sED = "" + Request.QueryString("ed"); if(sED == "undefined" || sED == "null") sED = "";
if(sED != "")
{
sPR += " AND [DATE]<=#" + SQLSTR(sED) + "#"
}
}
else
{
var nCT = parseInt("" + Request.QueryString("ct")); if(isNaN(nCT)) nCT = 0;
if(nCT > 0)
{
sPR += " AND DATEDIFF('h',[DATE],NOW())<" + nCT;
}
}
SQL = "SELECT COUNT(*) FROM [REFERRER]" + sPR;
oRS = oConnect.Execute(SQL)
if(!oRS.EOF)
{
nTotal = oRS(0).Value;
}
oRS.Close();
SQL = "SELECT [NAME],COUNT(*) FROM [REFERRER]" + sPR + " GROUP BY [NAME] ORDER BY COUNT(*) DESC";
oRS = oConnect.Execute(SQL);
var n = 0;
var oData = new Array();
while(!oRS.EOF)
{
oData[n] = new Array();
oData[n][0]= oRS(0).Value;
oData[n][1] = oRS(1).Value;
n++;
oRS.MoveNext();
}
oRS.Close();
if(n > 0)
{
dispTOP();
}
else
{
dispNone();
}
oRS = null;
oConnect.Close(); oConnect = null;
function Write(sHTML)
{
Response.Write("document.write(\"" + sHTML + "\");\n");
}
function makeURL(sName,sURL)
{
if(sURL.indexOf("http://") == 0)
{
sURL = sURL.substring(7);
}
return "<a href=\\\"http://" + sURL + "\\\">" + sName + "</a>";
}
function dispNone()
{
Write("<h1><br>There is no data in the range you requested</h1>");
}
function dispTOP()
{
// 显示
Write("<br><font color='#0080FF' face='Georgia, Times New Roman, Times, serif'>Top Refering Sites</font><BR><br>");
Write("<table>");
Write("<tr><td align='center'> Rank </td>")
Write("<td align='center'> Refering Site </td>");
Write("<td align='center'> Times </td>");
Write("<td align='center'> Graph </td>")
Write("<td align='center'> Percent </td></tr>");
for(i=0;i<n;i++)
{
if(oData[i][1] > 0)
{
Write("<tr>");
Write("<td align='center'>" + (i + 1) + "</td>");
if(oData[i][0] == "Not Avalible")
{
Write("<TD> </td><TD align='center'>" + oData[i][1] + "</td>");
}
else
{
Write("<TD> " + oData[i][0] + " </td><TD align='center'>" + oData[i][1] + "</td>");
}
Write("<TD>");
// 百分比
var nPct = oData[i][1]/nTotal*100;
Write("<img src='/lib/images/percent.gif' border=0 height='10px' width='" + nPct*2 + "px'>");
Write("</TD>");
Write("<TD align='center'> " + nPct + "% </td>");
Write("</TR>");
}
}
Write("</table>");
}
%>
document.write("</strong></font></td><td> </td></tr></table>");
refcnt.js
function __refcnt()
{
document.write("<sc");
document.write("ript language=javascript src='/lib/refcnt.asp?to=" + document.location + "'>");
document.write("</sc");
document.write("ript>");
}
__refcnt();
refcon.asp
<%
var oConnect = Server.CreateObject("ADODB.Connection");
oConnect.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\OSProject\\Public\\referrer\\dat\\refdb.mdb;Persist Security Info=False");
function SQLSTR(sSQL)
{
return sSQL.replace("'", "''");
}
%>