网站总访问量代码
1. 在asp.net中网站的总访问量怎么做啊 谢谢哈 要具体代码与过程哦 !
Global.asax文件统计网站的总访问量
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
int count = 0;
StreamReader srd;
//取得文件的实际路径
string file_path = Server.MapPath("counter.txt");
//打开文件进行读取
srd = File.OpenText(file_path);
while (srd.Peek() != -1)
{
string str = srd.ReadLine();
count = int.Parse(str);
}
srd.Close();
object obj = count;
//将从文件中读取的网站访问量存放在Application对象中
Application["counter"] = obj;
}
void Application_End(object sender, EventArgs e)
{
// 在应用程序关闭时运行的代码
int Stat = 0;
Stat = (int)Application["counter"];
string file_path = Server.MapPath("counter.txt");
StreamWriter srw = new StreamWriter(file_path, false);
srw.WriteLine(Stat);
srw.Close();
}
void Application_Error(object sender, EventArgs e)
{
// 在出现未处理的错误时运行的代码
}
void Session_Start(object sender, EventArgs e)
{
// 在新会话启动时运行的代码
Application.Lock();
//数据累加
int Stat = 0;
//获取Application对象中保存的网站总访问量
Stat = (int)Application["counter"];
Stat += 1;
object obj = Stat;
Application["counter"] = obj;
//将数据记录写入文件
string file_path = Server.MapPath("counter.txt");
StreamWriter srw = new StreamWriter(file_path, false);
srw.WriteLine(Stat);
srw.Close();
Application.UnLock();
}
void Session_End(object sender, EventArgs e)
{
// 在会话结束时运行的代码。
// 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
// InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
// 或 sqlServer,则不会引发该事件。
}
2. JS 精确统计网站访问量的实例代码
这篇文章介绍了JS精确统计网站访问量的实例代码 有需要的朋友可以参考一下 复制代码 代码如下: lishixin/Article/program/java/JSP/201311/20528
3. asp记录网站总访问量完整代码
<%
dim count,path
count= 1
path = server.Mappath("count.txt")
Set fs=CreateObject("scripting.filesystemobject")
if(fs.FileExists(path))then
Set hs=fs.opentextfile(path)
count=hs.ReadLine
if session("iscount")="" then
session("iscount")="iscount"
count=count+1
end if
hs.close
Set hs=fs.opentextfile(path,2,true)
hs.writeline(count)
else
Set hs=fs.createtextfile(path)
hs.writeline(1)
end if
response.write "您是第"&count&"位访问者!"
hs.close
set fs=nothing
%>
这样就可以, 每次新打开浏览器才会记录,而不是每次刷新就记录,如果你要每次刷新都记录也可以,追问下,我改改
4. 怎样在asp.net网站上写访问量的代码统计
看到你写的代码,我想告诉你,访问量应该存在application中, 而不是在session,因为访问量是对整站而言的。 当然你也可以使用cookie实现, 不过不推荐使用。 public int count; protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { try { this.count = Convert.ToInt32(Application["count"]); Application["count"]=this.count +1;//将访问次数加1 } catch (Exception ee) { } } } 以上代码简单的展示了实现思路, 希望可以帮你解决!
5. 求一个网站访问量代码:代码中包含总访问量,今日访问量,昨日访问量
需要在你的网站布上统计代码,这是前提,然后可以选择设置统计代码的展示样式。用网络统计等统计工具都可以实现的。
6. 网站访问量统计java代码
public class Counter {
private int count;
// 每访问一次,计数器自加一
public int getCount() {
return ++count;
}
public void setCount(int count) {
this.count = count;
}
}
<%-- 定义一个 session 范围内的计数器 记录个人访问信息 --%>
<jsp:useBean id="personCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="session" />
<%-- 定义一个 application 范围内的计数器 记录所有人的访问信息 --%>
<jsp:useBean id="totalCount" class="com.helloweenvsfei.jspweb.bean.Counter" scope="application" />
<div align="center">
<form action="method.jsp" method="get">
<fieldset style='width: 300'>
<legend>计数器</legend>
<table align="center" width="400">
<tr>
<td width=150 align="right" style="font-weight:bold; ">您的访问次数:</td>
<td>
<%-- 获取个人的 访问次数 --%>
<jsp:getProperty name="personCount" property="count" /> 次
</td>
</tr>
<tr>
<td width=150 align="right" style="font-weight:bold; ">总共的访问次数:</td>
<td>
<%-- 获取所有人的 访问次数 --%>
<jsp:getProperty name="totalCount" property="count" /> 次
</td>
</tr>
</table>
</fieldset>
</form>
</div>
希望你能帮到你
7. 网站访问量统计java代码怎样写
<DIV class="h">
<%-- 记录网站访问次数 --%>
<%
Integer counter = (Integer)application.getAttribute("counter"); //先从application里面获取计数器的key的值
if(counter==null){
//如果该值为null,说明第一次访问
application.setAttribute("counter",1);
counter=(Integer)application.getAttribute("counter");
}else {
//如果该值不为空,取出来进行累加
int i = counter.intValue();
i++;
application.setAttribute("counter",i);//累加后再放进去
}
%>
<% User user =(User)session.getAttribute("users"); %>
<%="欢迎"+user.getName() %> |您是第<%=counter.intValue()%>位访客
</DIV>
谢谢~
8. 有统计网站访问量的代码吗
假定数据存在 abc.mdb中
abc.mdb中字段如下:
序号(自动)
日期(访客进入时间)
电脑(IP地址)
来自(如果访客从www.0086it.com/?f=hello 进入本站,那会显示“hello”)
地址(通过对IP地址分析后知道的地址(如:中国网通或北京大学))
在网站首页中插入以下代码:
《%
if session("0086it")<>1 then
'上面一行防止刷新给统计造成不准。
dsntemp=server.mappath("abc.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&dsntemp
set rs=server.createobject("adodb.recordset")
rs.open "db",conn,1,3
rs.addnew
rs("日期")=now()
rs("电脑")=request.servervariables("remote_addr")
rs("来自")=request.querystring("f")&"◆"&request.serverVariables("Http_REFERER")
rs("地址")=session("laizi")
'session("laizi")的值的取得不作具体介绍,是由另一程序将访者ip地址与另外一个数据库对比中得出来“详细汉字地名,相当于IP地址查询软件中的功能)
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
session("0086it")=1
end if
%》
这样,每次访客访问我站,就可以记录他的信息。
当然,我还需要有一个程序来读后台。
程序如下:
《%
'**********************************
'
' 访 客 统 计 系 统'
'
' 程序设计 : 姜川
' [email protected]
' COPY请保留以上信息
'
'*********************************
'
response.expires=0
Response.Buffer=True
dim id
id=request.querystring("id")
if id="" then
id=50
end if
%》
《html》
《style type="text/css"》
《link rel="stylesheet" href="../css/one.css" type="text/css"》
《!--
.jiangc { font-size: 9pt; line-height: 12pt}
a { color: #FF0000; text-decoration: none}
a:hover { text-decoration: underline}
--》
《/style》
《body bgcolor="#FFFFFF"》
《%
dsntemp=server.mappath("abc.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid=admin;password=hello;dbq="&dsntemp
if request.querystring("cha")《》"" then
sql ="select * from db where 来自 like '%"&request.form("cha")&"%' order by 日期 DESC"
else
sql ="select * from db order by 序号 DESC"
end if
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
%》
《p align="center"》《br》
《font face="黑体"》访 问 统 计 系 统《/font》《/p》
《table width="700" border="0" cellspacing="1" cellpadding="0" align="center" class="jiangc" bgcolor="#000000"》
《form name="form1" method="post" action="?cha=1"》 《tr》
《td height="24" bgcolor="#ECF9FF" align="center"》 [ 共 《font color=red》《%=rs.recordcount%》《/font》
条记录 ] 列出最近 《a href="?id=100"》100《/a》 《a href="?id=300"》300《/a》 《a href="?id=500"》500《/a》
《a href="?id=1000"》1000《/a》 《a href="?id=3000"》3000《/a》 《a href="?id=5000"》5000《/a》
《a href="?ID=《%=rs.recordcount%》&ID2=all"》所有《/a》 记录
《input type="text" name="cha" class="jiangc" size="12"》
《input type="submit" name="Submit" value="查" class="jiangc"》
《/td》
《/tr》 《/form》
《/table》
《table width="100%" border="0" cellspacing="0"》
《tr》
《td height=2》《/td》
《/tr》
《/table》
《table border="0" cellspacing="1" cellpadding="2" bordercolorlight="#CCCCCC" bordercolordark="#FFFFFF" class="jiangc" align="center" bgcolor="#999999"》
《tr bgcolor="#CCCCCC"》
《td》 序号《/td》
《td》记录中总编号《/td》
《td》访问者进入日期《br》
0000000000000000000《/td》
《td》 访问者电脑IP地址《/td》
《td》 地区《/td》
《td》 来自《/td》
《/tr》
《%
while not rs.eof and i《 cint(id)
i=i+1
%》
《tr bgcolor="#FFFFFF"》
《td align="center"》《font color=cccccc》《%=i%》《/font》《/td》
《td align="center"》 《%=rs("序号")%》 《/td》
《td》
《%
if rs("日期") 》 date() then
response.write "《font color=red》"&rs("日期")&"《/font》"
else
response.write rs("日期")
end if%》
《/td》
《td》
《%if rs("电脑")="221.215.99.61" then response.write "*" else response.write rs("电脑") end if%》
《/td》
《td》
《%=rs("地址")%》
《/td》
《td》
《%if instr(rs("来自"),"◆")《》0 then
response.write "《a href='"&right(rs("来自"),len(rs("来自"))-instr(rs("来自"),"◆"))&"' target='_blank'》"&rs("来自")&"《/a》"
end if%》
《/td》
《/tr》
《%
rs.movenext
wend
%》
《/table》
《br》
《table width="700" border="0" cellspacing="1" cellpadding="10" align="center" class="jiangc" bgcolor="#CCCCCC" bordercolor="#0000CC"》
《tr》
《td bgcolor="#EFEFEF"》备 注:《%if request.querystring("id2")=all then%》只列出最近的 《font color=red》《%=id%》《/font》 条记录《br》
《%else%》
系统列出了所有访问记录《br》
《%end if%》
设 计:[email protected](MSN)《br》
设计日期:2003年03月《/td》
《/tr》
《/table》
《/html》
9. 网站访问量统计代码
很简单你只要进入http://www.51.la/这里注册以后登陆.输入自己的网站地址就会生成一段代码直接复制粘贴到自己网站就可以了.很好用的.我用好久了.希望能对你有用!