今天您统计了么- -没?(统计程序~web)
- -统计是现在觉定网站生存发展的方向~~至少昨天还是~~小型的~~
统计来源
统计Ip
统计客户端的信息
-------------------来来~~按照常理先看看逻辑分析图
1在要统计的页面潜入<script src="MMWebCount.ashx?webid=007&style=0" />上面画图的时候手哆嗦了几下.并且扩展名写错了~~一画图我就紧张~~因为小学画图不及格阿
2当有web访问的时候-连接统计网站的MyStatHandler-然后有MyStatHandler返回脚本2
3再次通讯得到脚本4
2返回
"document.write(""<script //--------------document.referrer表示来源地址, screen.width表示客户端脚本的宽度
src=""+url+""/StatInfoHandler.ashx?style=""+style+""&webid=""+webid+""&referer=""+escape(document.referrer)+""&screenwidth=""+screen.width+""></script>"");";
4返回的脚本log document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/log.gif border=0 alt={2}></a>"")"
--------------------MMWebCount.ashx
//---StatInfoHandler.ashx--这个用来接收参数的阿
//--他们是怎么工作的呢??
统计来源
统计Ip
统计客户端的信息
-------------------来来~~按照常理先看看逻辑分析图
1在要统计的页面潜入<script src="MMWebCount.ashx?webid=007&style=0" />上面画图的时候手哆嗦了几下.并且扩展名写错了~~一画图我就紧张~~因为小学画图不及格阿
2当有web访问的时候-连接统计网站的MyStatHandler-然后有MyStatHandler返回脚本2
3再次通讯得到脚本4
2返回
"document.write(""<script //--------------document.referrer表示来源地址, screen.width表示客户端脚本的宽度
src=""+url+""/StatInfoHandler.ashx?style=""+style+""&webid=""+webid+""&referer=""+escape(document.referrer)+""&screenwidth=""+screen.width+""></script>"");";
4返回的脚本log document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/log.gif border=0 alt={2}></a>"")"
--------------------MMWebCount.ashx
<%@ WebHandler Language="C#" Class="MMWebCount" %>
using System;
using System.Web;
public class MMWebCount : IHttpHandler
{
/// <summary>
/// 返回统计的Log
/// </summary>
private const String resScript3 = @"document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/illegal.gif border=0 alt={2}></a>"")";
protected const String resScript1 = @"document.write(""<script>var url='{0}';var style='{1}';var webid='{2}'</script>"");";
protected const String resScript2 =
@"document.write(""<script //--------------document.referrer表示来源地址, screen.width表示客户端脚本的宽度
src=""+url+""/StatInfoHandler.ashx?style=""+style+""&webid=""+webid+""&referer=""+escape(document.referrer)+""&screenwidth=""+screen.width+""></script>"");";
public void ProcessRequest(HttpContext context)
{
String webid = context.Request.QueryString["webid"];
//------------------设置个默认的
if (String.Empty == webid) webid = "007";
//-------------resScript1中包含的脚本,0位置输,GetBaseUrl() 就是网站的地址,1位置输出style ,2输出网站的id
String str = String.Format(resScript1, GetBaseUrl(), request.QueryString["style"], request.QueryString["webid"]);
//----------上面的字符串+ resScript2的脚本
context.Response.Write(str + "\n" + resScript2);
context.Response.End();
}
public bool IsReusable
{get
{
return true;}
}
/// <summary>
/// 得到当前网站的基地址
/// </summary>
/// <returns></returns>
protected String GetBaseUrl()
{//--------当前网站的地址
return "http://localhost/MMyou";
}
}
using System;
using System.Web;
public class MMWebCount : IHttpHandler
{
/// <summary>
/// 返回统计的Log
/// </summary>
private const String resScript3 = @"document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/illegal.gif border=0 alt={2}></a>"")";
protected const String resScript1 = @"document.write(""<script>var url='{0}';var style='{1}';var webid='{2}'</script>"");";
protected const String resScript2 =
@"document.write(""<script //--------------document.referrer表示来源地址, screen.width表示客户端脚本的宽度
src=""+url+""/StatInfoHandler.ashx?style=""+style+""&webid=""+webid+""&referer=""+escape(document.referrer)+""&screenwidth=""+screen.width+""></script>"");";
public void ProcessRequest(HttpContext context)
{
String webid = context.Request.QueryString["webid"];
//------------------设置个默认的
if (String.Empty == webid) webid = "007";
//-------------resScript1中包含的脚本,0位置输,GetBaseUrl() 就是网站的地址,1位置输出style ,2输出网站的id
String str = String.Format(resScript1, GetBaseUrl(), request.QueryString["style"], request.QueryString["webid"]);
//----------上面的字符串+ resScript2的脚本
context.Response.Write(str + "\n" + resScript2);
context.Response.End();
}
public bool IsReusable
{get
{
return true;}
}
/// <summary>
/// 得到当前网站的基地址
/// </summary>
/// <returns></returns>
protected String GetBaseUrl()
{//--------当前网站的地址
return "http://localhost/MMyou";
}
}
//---StatInfoHandler.ashx--这个用来接收参数的阿
<%@ WebHandler Language="C#" Class="StatInfoHandler" %>
using System;
using System.Web;
public class StatInfoHandler : IHttpHandler
{
protected const String _isValid = "true";
private const String resCode2 = @"document.location.href='{0}/illegalweb.aspx?errmsg={1}'";
private const String resCode1 = @"document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/log.gif border=0 alt={2}></a>"")";
private Int64 _createTime = DateTime.Now.Ticks;
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
// if 被统计页面是无效页面
String judge = IsValid(Request);
if (!_isValid.Equals(judge))
{
// 输出出错提示
String str = String.Format(resCode2, GetBaseUrl(), judge);
Response.Write(str);
Response.End();
}
try
{
String style = Request.QueryString["style"];
//---如果!=与no代表用户使用log
if (style != "no")
{
//---输出统计网站的图标-------------------------------------0统计网站的地址—1统计网站的log存放地址
String str = String.Format(resCode1, GetBaseUrl(), GetBaseUrl(), "网站访问统计实例");
Response.Write(str);
}
//------ StatInfo信息提取操作
StatInfo statInfo = BuildStatInfo(Request);
using (MM.ICount mm = new MM.DataBase())//--连接数据库
{
if (mm.Open(System.Configuration.ConfigurationManager.AppSettings["ConnStrReporter"]))
{
//----------------这个消息记录到数据库中
mm.Insert(statInfo);
}
}
}
catch (Exception ex)
{
}
finally
{
Response.End();
}
}
public bool IsReusable
{
get { return true; }
}
//-------------验证网站id的
protected String IsValid(HttpRequest request)
{
String webid = request.QueryString["webid"];
if (webid == String.Empty)
return "需要输入一个webid参数";
if (0 == int.Parse(webid))
{
//---如果=0则返回警告信息
return invalidwebid;
}
return _isValid;
}
public StatInfo BuildStatInfo(HttpRequest Request)
{
//--------------存放提取信息D
MMoo dInfo = new StatInfo();
dInfo.WebId = int.Parse(Request.QueryString["webid"]);//-----放置网站id
dInfo.ClientIP = Request.UserHostAddress;//---------------客户端ip地址
dInfo.URL = Request.ServerVariables["HTTP_REFERER"];//--页面的url—注意不要用Request.url;
String[] userLangs = Request.UserLanguages;//-------客户端语言组
if (userLangs.Length > 0)
dInfo.UserLanguage = userLangs[0];//------首选语言
else dInfo.UserLanguage = String.Empty;
dInfo.RefUrl = Request.QueryString["referer"];//-----来源地址
dInfo.PlatForm = Request.Browser.Platform;//--------使用的系统
dInfo.Browser = Request.Browser.Browser;//--------浏览器
dInfo.Client = new Client(Request.UserAgent, Request.QueryString["screenwidth"]);//--屏幕宽度
return dInfo;
}
protected String GetBaseUrl()
{
return "http://localhost/MMyou";
}
//实体类
public class MMoo
{
//--省略
}
///连接数据库的类
public class MM
{
//--省略
}
}
using System;
using System.Web;
public class StatInfoHandler : IHttpHandler
{
protected const String _isValid = "true";
private const String resCode2 = @"document.location.href='{0}/illegalweb.aspx?errmsg={1}'";
private const String resCode1 = @"document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/log.gif border=0 alt={2}></a>"")";
private Int64 _createTime = DateTime.Now.Ticks;
public void ProcessRequest(HttpContext context)
{
HttpRequest Request = context.Request;
HttpResponse Response = context.Response;
// if 被统计页面是无效页面
String judge = IsValid(Request);
if (!_isValid.Equals(judge))
{
// 输出出错提示
String str = String.Format(resCode2, GetBaseUrl(), judge);
Response.Write(str);
Response.End();
}
try
{
String style = Request.QueryString["style"];
//---如果!=与no代表用户使用log
if (style != "no")
{
//---输出统计网站的图标-------------------------------------0统计网站的地址—1统计网站的log存放地址
String str = String.Format(resCode1, GetBaseUrl(), GetBaseUrl(), "网站访问统计实例");
Response.Write(str);
}
//------ StatInfo信息提取操作
StatInfo statInfo = BuildStatInfo(Request);
using (MM.ICount mm = new MM.DataBase())//--连接数据库
{
if (mm.Open(System.Configuration.ConfigurationManager.AppSettings["ConnStrReporter"]))
{
//----------------这个消息记录到数据库中
mm.Insert(statInfo);
}
}
}
catch (Exception ex)
{
}
finally
{
Response.End();
}
}
public bool IsReusable
{
get { return true; }
}
//-------------验证网站id的
protected String IsValid(HttpRequest request)
{
String webid = request.QueryString["webid"];
if (webid == String.Empty)
return "需要输入一个webid参数";
if (0 == int.Parse(webid))
{
//---如果=0则返回警告信息
return invalidwebid;
}
return _isValid;
}
public StatInfo BuildStatInfo(HttpRequest Request)
{
//--------------存放提取信息D
MMoo dInfo = new StatInfo();
dInfo.WebId = int.Parse(Request.QueryString["webid"]);//-----放置网站id
dInfo.ClientIP = Request.UserHostAddress;//---------------客户端ip地址
dInfo.URL = Request.ServerVariables["HTTP_REFERER"];//--页面的url—注意不要用Request.url;
String[] userLangs = Request.UserLanguages;//-------客户端语言组
if (userLangs.Length > 0)
dInfo.UserLanguage = userLangs[0];//------首选语言
else dInfo.UserLanguage = String.Empty;
dInfo.RefUrl = Request.QueryString["referer"];//-----来源地址
dInfo.PlatForm = Request.Browser.Platform;//--------使用的系统
dInfo.Browser = Request.Browser.Browser;//--------浏览器
dInfo.Client = new Client(Request.UserAgent, Request.QueryString["screenwidth"]);//--屏幕宽度
return dInfo;
}
protected String GetBaseUrl()
{
return "http://localhost/MMyou";
}
//实体类
public class MMoo
{
//--省略
}
///连接数据库的类
public class MM
{
//--省略
}
}
//--他们是怎么工作的呢??
MyStatHandler 对前台 1请求
StatInfoHandler 对前台3请求
MMoo---收集统计信息
---------------------收集就到这里了了
知说说显示的页-统计流的时候看百分比
23:18:31
//---------------前台
<asp:DataGrid ID="VoteList" Runat="server" CssClass="GbText" BorderColor="#CC9966" AutoGenerateColumns="False" DataKeyField="VoteID">
<HeaderStyle BackColor="Orange" width="600px"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="统计流量图" ItemStyle-BorderWidth="1">
<ItemStyle Width="200px"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Id")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="流量百分比" ItemStyle-HorizontalAlign="Left" ItemStyle-BorderWidth="1">
<ItemStyle Width="300px"></ItemStyle>
<ItemTemplate>
//---------------------绘图的方法----------到后台取得百分比
<asp:Image ID="voteImage" Runat="server" Height="20" Width='<%# FormatVoteImage(FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").ToString()))%>' ImageUrl="Images/vote.gif">
</asp:Image>
<%# FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").ToString())%>
%
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="多少流量" ItemStyle-BorderWidth="1">
<ItemStyle Width="100px"></ItemStyle>
<ItemTemplate>
<asp:Label ID="VoteCount" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"VoteCount")%>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
//---------------------------------------------------后台
//------------------算百分比
public int FormatVoteCount(String voteCount)
{
if (voteCount.Length <= 0)
{
return (0);
}
if (voteTotal > 0)
{
return ((Int32.Parse(voteCount) * 100 / voteTotal));
}
return (0);
}
public int FormatVoteImage(int voteCount)
{
return (voteCount * 3);
}
protected void WebOnlineVoteBtn_Click(object sender, EventArgs e)
{
}
<asp:DataGrid ID="VoteList" Runat="server" CssClass="GbText" BorderColor="#CC9966" AutoGenerateColumns="False" DataKeyField="VoteID">
<HeaderStyle BackColor="Orange" width="600px"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="统计流量图" ItemStyle-BorderWidth="1">
<ItemStyle Width="200px"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"Id")%>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="流量百分比" ItemStyle-HorizontalAlign="Left" ItemStyle-BorderWidth="1">
<ItemStyle Width="300px"></ItemStyle>
<ItemTemplate>
//---------------------绘图的方法----------到后台取得百分比
<asp:Image ID="voteImage" Runat="server" Height="20" Width='<%# FormatVoteImage(FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").ToString()))%>' ImageUrl="Images/vote.gif">
</asp:Image>
<%# FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").ToString())%>
%
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="多少流量" ItemStyle-BorderWidth="1">
<ItemStyle Width="100px"></ItemStyle>
<ItemTemplate>
<asp:Label ID="VoteCount" Runat="server">
<%# DataBinder.Eval(Container.DataItem,"VoteCount")%>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
//---------------------------------------------------后台
//------------------算百分比
public int FormatVoteCount(String voteCount)
{
if (voteCount.Length <= 0)
{
return (0);
}
if (voteTotal > 0)
{
return ((Int32.Parse(voteCount) * 100 / voteTotal));
}
return (0);
}
public int FormatVoteImage(int voteCount)
{
return (voteCount * 3);
}
protected void WebOnlineVoteBtn_Click(object sender, EventArgs e)
{
}