⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stat.aspx.cs

📁 阿江酷站统计系统ASP.Net版,可以直接使用。和现有的网站合并就可以了。提供详细的IP分析。
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace counter
{
	/// <summary>
	/// stat 的摘要说明。
	/// </summary>
	public class stat : System.Web.UI.Page
	{
		public static DataView dv;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			//网页立即超时,防止漏统计
			Response.Expires=0;

			//被访问页面
			System.Collections.Specialized.NameValueCollection  ServerVariables = System.Web.HttpContext.Current.Request.ServerVariables;
			string strvpage;
			
			if(ServerVariables["HTTP_REFERER"]!=null)
			{
				strvpage=ServerVariables["HTTP_REFERER"].ToString();
			}
			else
			{
				strvpage="";
			}

			if(strvpage != "" && strvpage.Substring(strvpage.Length-1,1) == "/") strvpage=strvpage.Substring(0,strvpage.Length-1);

			//检查是否强制页面
			DataSet myds = new DataSet();
			myds = counter.SQLConn.ExecuteSqlForDataSet("select * from CounterInfo");
			dv=myds.Tables[0].DefaultView;

			string mNameEn=dv[0].Row["myNameEn"].ToString();
			
			int intonlylen1=(int)dv[0].Row["onlythesite1"].ToString().Length;
			int intonlylen2=(int)dv[0].Row["onlythesite2"].ToString().Length;

			bool canstat=false;
			if (intonlylen1==0 && intonlylen2==0)  canstat=true;
			if (intonlylen1==0 && intonlylen2!=0 && strvpage.Substring(0,intonlylen2)==dv[0].Row["onlythesite2"].ToString()) canstat=true;
			if (intonlylen1!=0 && intonlylen2==0 && strvpage.Substring(0,intonlylen1)==dv[0].Row["onlythesite1"].ToString()) canstat=true;
			if (intonlylen1!=0 && intonlylen2!=0 && (strvpage.Substring(0,intonlylen1)==dv[0].Row["onlythesite1"].ToString() || strvpage.Substring(0,intonlylen2)==dv[0].Row["onlythesite2"].ToString())) canstat=true;

			if(canstat)
			{
				//==============记录相关数据==============

				//访客IP
				string strvip=ServerVariables["REMOTE_ADDR"].ToString();
				
				//来路
				string strvcome;
				if(Request.QueryString["referer"]!=null)
				{
					strvcome=Request.QueryString["referer"].ToString();
				}
				else
				{
					strvcome="";
				}
				if(strvcome!="" && strvcome.Substring(strvcome.Length-1,1)=="/") strvcome=strvcome.Substring(0,strvcome.Length-1);

				//时间
				int intvyear=int.Parse(DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Year.ToString());
				int intvmonth=int.Parse(DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Month.ToString());
				int intvday=int.Parse(DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Day.ToString());
				int intvhour=int.Parse(DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Hour.ToString());
				string strvtime=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).ToString();
				int intvweek=(int)DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).DayOfWeek;

				//客户端软件使用情况
				string useragent=ServerVariables["HTTP_USER_AGENT"].ToString();
				
				//浏览器
				string strvsoft="Other";
				string[,] arvsoft=new string[,]{{"NetCaptor","NetCaptor"},{"MSIE 6","MSIE 6.x"},{"MSIE 5","MSIE 5.x"},{"MSIE 4","MSIE 4.x"},{"Netscape","Netscape"},{"Opera","Opera"}};
				for(int i=0;i<6;i++)
				{
					if(useragent.IndexOf(arvsoft[i,0].ToString())>0)
					{
						strvsoft=arvsoft[i,1];
						break;
					}
				}
				
				//操作系统
				string strvOS="Other";
				string[,] arvos=new string[,]{{"Windows NT 5.0","Win2k"},{"Windows NT 5.1","WinXP"},{"Windows NT 5.2","Win2k3"},{"Windows NT","WinNT"},{"Windows 9","Win9x"},{"unix","类Unix"},{"linux","类Unix"},{"SunOS","类Unix"},{"BSD","类Unix"},{"Mac","Mac"}};
				for(int i=0;i<10;i++)
				{
					if(useragent.IndexOf(arvos[i,0].ToString())>0)
					{
						strvOS=arvos[i,1];
						break;
					}
				}


				//屏幕宽度
				int intvwidth=800;
				if(Request.QueryString["screenwidth"] !=null) intvwidth=int.Parse(Request.QueryString["screenwidth"].ToString());

				//访问者所在地区,从独立数据库读取IP信息
				DataSet myds1 = new DataSet();
				DataView dv1=new DataView();
				long lgipnow=getcip(strvip);

				myds1 = counter.SQLConn.ExecuteSqlForDataSet("select * from ip where (onip<=" + lgipnow + " and offip>=" + lgipnow +")");				
				dv1=myds1.Tables[0].DefaultView;
				dv1.Table.AcceptChanges();
				string strvwhere="未知";
				string strvwheref="";
				if(dv1.Count!=0)
				{
					strvwhere=dv1[0].Row["addj"].ToString();
					strvwheref=dv1[0].Row["addf"].ToString();
				}				
				dv1.Dispose();

				//检查是否属于刷新
				string is_echo="False";
				if(dv[0].Row["is_ipcheck"].ToString() == "True")
				{					
					System.Web.HttpCookie readcookie=Request.Cookies[mNameEn + "echo"];
					if(readcookie != null && readcookie.Values["lao"]!=null) is_echo=readcookie.Values["lao"].ToString();
					if (is_echo!="True")
					{
						System.Web.HttpCookie cookie= new HttpCookie(mNameEn + "echo");
						cookie.Expires=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).AddDays(0.01);
						cookie.Values.Add("lao","True");
						Response.AppendCookie(cookie);
					}
				}

				//统计在线人数
				DateTime newtime=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).AddMinutes(-20);
				myds1 = counter.SQLConn.ExecuteSqlForDataSet("select vip from CounterView where vtime >='" + newtime + "' group by vip");
				dv1=myds1.Tables[0].DefaultView;
				dv1.Table.AcceptChanges();
				int intvonline=dv1.Count;
				dv1.Dispose();

				//===============写主数据库================
				if((dv[0].Row["is_online"].ToString() == "True" && is_echo != "True") || dv[0].Row["is_online"].ToString() == "False")
				{
					string strSql="insert into CounterView values('"+intvyear+"','";
					strSql+=intvmonth+"','";
					strSql+=intvday+"','";
					strSql+=intvhour+"',N'";
					strSql+=strvtime+"','";
					strSql+=intvweek+"',N'";
					strSql+=strvip+"',N'";
					strSql+=strvwhere+"',N'";
					strSql+=strvwheref+"',N'";
					strSql+=strvcome+"',N'";
					strSql+=strvpage+"',N'";
					strSql+=strvsoft+"',N'";
					strSql+=strvOS+"','";
					strSql+=intvwidth+"',0,0,0)";

					counter.SQLConn.ExecuteSql(strSql);

				}

				//===============读写简数据库===============
				if((dv[0].Row["is_online"].ToString() == "True" && is_echo != "True") || dv[0].Row["is_online"].ToString() == "False")
				{
					myds1=counter.SQLConn.ExecuteSqlForDataSet("select * from CountContent");
					dv1=myds1.Tables[0].DefaultView;
					dv1.Table.AcceptChanges();
					if(dv1.Count==0)
					{
						dv1.Dispose();
						string strjSql="insert into CountContent values('";
						strjSql+= 1+"','";
						strjSql+= 0+"','";
						strjSql+= DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Date.ToShortDateString() +"','";
						strjSql+= 1+"','";
						strjSql+= DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).ToString()+"','";
						strjSql+= 1+"','";
						strjSql+= DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Date.ToShortDateString()+"')";

						counter.SQLConn.ExecuteSql(strjSql);

					}
					else
					{
						int inttoday=int.Parse(dv1[0].Row["today"].ToString());
						int intyesterday=int.Parse(dv1[0].Row["yesterday"].ToString());
						string strolddate=dv1[0].Row["vdate"].ToString();
						int intvtop=int.Parse(dv1[0].Row["vtop"].ToString());
						string strstarttime=dv1[0].Row["starttime"].ToString();
						int intvhigh=int.Parse(dv1[0].Row["vhigh"].ToString());
						string strvhightime=dv1[0].Row["vhightime"].ToString();
						dv1.Dispose();

						int intdatecha=(int)(DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Subtract(DateTime.Parse(strolddate)).TotalDays);
						switch(intdatecha)
						{
								//上条记录是今天的
							case 0:
								inttoday+=1;
								break;

								//上条记录是昨天的
							case 1:
								intyesterday=inttoday;
								inttoday=1;
								strolddate=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Date.ToShortDateString();
								break;

								//上条记录是若干天前的
							default:
								intyesterday=0;
								inttoday=1;
								strolddate=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Date.ToShortDateString();
								break;
						}

						if(inttoday>intvhigh)
						{
							intvhigh=inttoday;
							strvhightime=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).Date.ToShortDateString();
						}

						intvtop+=1;

						string strjSqlUpdate="update CountContent set ";
						strjSqlUpdate+="today="+inttoday+",";
						strjSqlUpdate+="yesterday="+intyesterday+",";
						strjSqlUpdate+="vdate='"+strolddate+"',";
						strjSqlUpdate+="vtop="+intvtop+",";
						strjSqlUpdate+="vhigh="+intvhigh+",";
						strjSqlUpdate+="vhightime='"+strvhightime+"'";

						counter.SQLConn.ExecuteSql(strjSqlUpdate);

					}

				}

				//读出数据
				myds1=counter.SQLConn.ExecuteSqlForDataSet("select * from CountContent");
				dv1=myds1.Tables[0].DefaultView;

				int inttoday1=int.Parse(dv1[0].Row["today"].ToString());
				int intyesterday1=int.Parse(dv1[0].Row["yesterday"].ToString());
				int intvtop1=int.Parse(dv1[0].Row["vtop"].ToString())+int.Parse(dv[0].Row["old_count"].ToString());
				int inthigh1=int.Parse(dv1[0].Row["vhigh"].ToString());
				string strhightime1=DateTime.Parse(dv1[0].Row["vhightime"].ToString()).Date.ToShortDateString();

				dv1.Dispose();

				//读写COOKIE,得到用户浏览量
				System.Web.HttpCookie readcookie1=Request.Cookies[mNameEn];
				int intvuser;
				if(readcookie1 != null && readcookie1.Values["lao"]!=null) 
				{
					intvuser=int.Parse(readcookie1.Values["lao"].ToString())+1;
				}
				else
				{
					intvuser=1;
				}

				System.Web.HttpCookie cookie1= new HttpCookie(mNameEn);
				cookie1.Expires=DateTime.Now.AddHours(int.Parse(dv[0].Row["adjtime"].ToString())).AddDays(int.Parse(dv[0].Row["CookieExpires"].ToString()));
				cookie1.Values.Add("lao",intvuser.ToString());
				Response.AppendCookie(cookie1);
				
				//写出HTML
				
				//程序及图像文件路径
				string strtheurl=ServerVariables["URL"].ToString();
				strtheurl=strtheurl.Substring(0,strtheurl.IndexOf("stat.aspx",0,strtheurl.Length));
				strtheurl="http://"+ServerVariables["HTTP_HOST"].ToString()+strtheurl;

				string style="";
				if(Request.QueryString["style"]!=null) style=Request.QueryString["style"].ToString();

				string outstr="";
				switch(style)
				{
					case "counter":		//LOGO
						outstr="<table width='88' border='0' cellspacing='0' cellpadding='0' height='31' background='" + strtheurl + "images/stat_counter.gif'><tr><td height='5' width='24'></td><td height='5' width='57'></td><td height='5' width='7'></td></tr><tr><td height='16'></td><td height='16' align='center' valign='top'><marquee behavior='loop' scrollDelay='100' scrollAmount='3' style='font-size: 12px; line-height=15px'><a href='" + strtheurl + "index.aspx' target='_blank' style='color: #ffffff; text-decoration: none'>";
						outstr+="<font face='Arial, Verdana, san-serif' color='#407526'>总访问量: " + intvtop1 + "&nbsp;最高访问量: " + inthigh1 + "&nbsp;最高量日期: " + strhightime1 + "&nbsp;今日访问: " + inttoday1 + " &nbsp;昨日访问: " + intyesterday1 + " &nbsp;您的访量: " + intvuser ;
						if(dv[0].Row["is_online"].ToString() == "True") outstr+=" &nbsp;在线人数: " + intvonline;
						outstr+="</font></a></marquee></td><td height='16'></td></tr><tr><td height='10'></td><td height='10'></td><td height='10'></td></tr></table>";
						break;

					case "icon":		//ICON
						outstr="<a href='" + strtheurl + "index.aspx' title='" + dv[0].Row["programname"].ToString() + "\\n总量: " + intvtop1 + "\\n最高访问量: " + inthigh1 + "\\n最高量日期: " + strhightime1 + "\\n今日: " + inttoday1 + "\\n昨日: " + intyesterday1 + "\\n您的: " + intvuser;
						if(dv[0].Row["is_online"].ToString() == "True") outstr+= "\\n在线: " + intvonline;
						outstr+="' target='_blank'><img border='0' src='" + strtheurl + "images/stat_icon.gif'></a>";
						break;

					case "flash":		//FLASH
						outstr="<embed src='" + strtheurl + "count.swf?cgi=" + strtheurl + "flash.aspx' type='application/x-shockwave-flash' width='" + dv[0].Row["FlashWidth"].ToString() + "' height='" +dv[0].Row["FlashHeight"].ToString() + "'></embed>";
						break;

					case "text":		//TEXT
						outstr=intvtop1.ToString();
						break;

					default:
						outstr="";
						break;
				}

				//输出
				string outputstr="document"+"."+"write(\""+outstr+"\")";
				Response.Write(outputstr);
			}

			else	//检查是否非法调用
			{
				Response.Write("document.write(" + "非法调用" + ")");
			}


		}


		public long getcip(string orignip)
		{
			string[] streachip=orignip.Split('.');
			long intcip=0;
			for(int i=0;i<4;i++)
			{
				intcip+=(long)(int.Parse(streachip[i])*System.Math.Pow(256,3-i));
			}
			return intcip;
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -