我们知道,Request.ServerVariables("HTTP_REFERER")可以获取来源网站的地址,因此我们可以通过这个数据来做一个小小的来源访问统计
新建一个数据库Sys_Referer:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Sys_Referer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Sys_Referer]
GO
CREATE TABLE [dbo].[Sys_Referer] (
[FSiteName] [varchar] (64) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[FStr] [varchar] (64) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[FCounts] [int] NOT NULL ,
[VisitTime] [datetime] NOT NULL
) ON [PRIMARY]
GOFSiteName:varchar ,64 ,not null , 来源站点名称(用户自定义)
FStr: varchar ,64 ,not null ,网址中的关键字(如google则取google.com)
FCounts: int, not null, 统计来访数
VisitTime: datetime, not null, 来访时间
关键代码:
Referer = CStr(Request.ServerVariables("HTTP_REFERER"))
If(Referer="") Then
Referer="直接访问"
End If
'Response.Write Referer
'Response.Write "<BR>"
Set Rs=Conn.Execute("Select FSiteName,FStr,FCounts From Sys_Referer ORDER BY FCounts Desc")
FSites=Rs.GetRows()
For i=0 To Ubound(FSites,2)
If(Instr(Referer,FSites(1,i))) Then
Conn.Execute("Update Sys_Referer Set FCounts=FCounts+1,VisitTime=getdate() Where FStr='"&FSites(1,i)&"'")
End If
'Response.Write FSites(0,i) & "["&FSites(2,i)&"]<BR>"
Next
FSites=NULL
Rs.Close
Set Rs=Nothing
本文地址:http://com.8s8s.com/it/it7485.htm