relaxlife.net最强计数器-利用操作ini文件来控制流量,也可用做系统设置
最强计数器-利用操作ini文件来控制流量,也可用做系统设置
function.asp
<%
rem =================================================================
rem = 函数文件:function.asp
rem = 测试文件:iniprofile.asp
rem = 说明:setprofile写入ini文件函数,getprofile读ini文件函数
rem = revision:1.01 beta
rem = 作者:熊氏英雄(cexo255)
rem = date:2005/04/22 02:00:00
rem = qq:30133499
rem = mysite:http://www.relaxlife.net
rem = 测试地址:http://www.relaxlife.net/2005/relaxlife/blogview.asp?logid=157
rem = 下载地址:http://www.relaxlife.net/2005/relaxlife/blogview.asp?logid=157
rem = qq群:4341998
rem = 适用:和delphi操作ini文件一样简单,最好是用在统计访问量,读写速度非常的快。
rem = 下版本预计改进:不能删除数据项和修改数据项,对数据的操作很全。
rem =================================================================
function readfile(filename)
dim fso, f
const forreading = 1, forwriting = 2, forappending = 8
set fso = createobject(“scripting.filesystemobject”)
set f = fso.opentextfile(server.mappath(filename), forreading, true)
on error resume next
readfile = f.readall
if err then
err.clear: f.close: :readfile = “” :exit function
end if
f.close
end function
sub writefile(filename,str)
dim fso, f
const forreading = 1, forwriting = 2, forappending = 8
set fso = createobject(“scripting.filesystemobject”)
set f = fso.opentextfile(server.mappath(filename), forwriting, true)
f.write str
f.close
end sub
’返回值1 为操作成功
function setprofile(strfilename, strsection, strname, strsave)
dim strtemp, strfileback, strreturn,editflag,flag:flag = true
strfileback = “me.tmp”
strtemp = readfile(strfilename)
if instr(1,strtemp,”[“&trim(strsection)&”]”)=0 then
if strtemp<>”” then
writefile strfilename,strtemp & vbcrlf & “[” & trim(strsection) & “]” & vbcrlf & trim(strname) & “=” & strsave & vbcrlf
else
writefile strfilename,strtemp & “[” & trim(strsection) & “]” & vbcrlf & trim(strname) & “=” & strsave & vbcrlf
end if
setprofile = 1
exit function
end if
const forreading = 1, forwriting = 2, forappending = 8
dim fso, f1, f2
set fso = createobject(“scripting.filesystemobject”)
set f1 = fso.opentextfile(server.mappath(strfilename), forreading, true)
set f2 = fso.opentextfile(server.mappath(strfileback), forwriting, true)
on error resume next
do while flag
editflag = 0
strtemp = f1.readline
if err then
err.clear
exit do
end if
strreturn = strtemp
f2.write strreturn+vbcrlf
if instr(1, trim(strtemp), “[“) <> 0 then
if trim(strtemp) = “[“&trim(strsection)&”]” then
editflag = 1
dim flag1:flag1=true
do while flag1
strtemp = f1.readline
if err then
err.clear
exit do
end if
if instr(1, trim(strtemp), trim(strname)) <> 0 then exit do ’找到所要修改的字段值
strreturn = strtemp
f2.write strreturn+vbcrlf
loop
if editflag = 1 then
strreturn = strname & “=” & strsave
f2.write strreturn+vbcrlf
end if
else
editflag = 2
end if
end if
loop
f1.close
f2.close
writefile strfilename,readfile(strfileback)
fso.deletefile(server.mappath(strfileback))
set fso = nothing
setprofile = 1
end function
’返回值empty 为操作失败
function getprofile(strfilename, strsection, strname)
dim strtemp,strchara, strcharb,flag:flag=true
dim fso, f1
strtemp = readfile(strfilename)
if instr(1,strtemp,”[“&trim(strsection)&”]”)=0 then
getprofile = empty
exit function
end if
const forreading = 1, forwriting = 2, forappending = 8
strsectiontemp = “”: strnametemp = “”: strreturn = “”
set fso = createobject(“scripting.filesystemobject”)
on error resume next
if err then
err.clear: getprofile = “”: f1.close: exit function
end if
set f1 = fso.opentextfile(server.mappath(strfilename), forreading, true)
do while flag
strchara = f1.read(1)
if strchara = “[” then
do while true
strcharb = f1.read(1)
if strcharb = “]” then exit do
strsectiontemp = strsectiontemp & strcharb
loop
end if
if strsectiontemp = strsection then
strchara = f1.read(2)
findflag = 1
exit do
else
findflag = 2
strsectiontemp = “”
end if
loop
if err then
err.clear: getprofile = “”: f1.close: exit function
end if
flag = true
do while flag
strnametemp = “”
do while true
strchara = f1.read(1)
if strchara <> “=” then
strnametemp = strnametemp & strchara ’得到名称
else
exit do
end if
loop
if strnametemp = strname then
strreturn = f1.readline ’如果找到与它匹配的字段名,就返回得到的值
getprofile = strreturn
exit function
else
strreturn = f1.readline ’如果未找到与它匹配的字段名,就继续找
if err then
err.clear: getprofile =empty : f1.close: exit function
end if
end if
loop
f1.close
getprofile = strreturn
exit function
end function
%>
&&&&&&&&&&&&&&& &&&&&&&&&&&&&&& &&用做计数器%%%%%%%%%%%%%%%%%
’count.ini
’[访问量]
’开始年=2005
’开始月=2
’密码=49ba59abbe56e057
’url=http://www.relaxlife.net
’name=放松生活网
’今天日期=2005年5月5日
’总访问量=8000
’2005年访问量=60
’2005年2月访问量=1000
’2005年3月访问量=1800
’2005年4月访问量=3000
’2005年5月访问量=3140
’今天的访问量=300
’昨天的访问量=315
’前天的访问量=380
———————–显示访问量————————
dispnum.asp
<link href=”css/styles.css” rel=”stylesheet” type=”text/css”>
<!–#include file=”function.asp” –>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″>
<title>由“放松生活网—-访问量计数器”支持</title>
<meta name=”description” content=”放松生活网—-访问量计数器,relaxlife.net,relaxlife,放松生活网,放松生活”>
<meta name=”keywords” content=”放松生活网—-访问量计数器,relaxlife.net,relaxlife,放松生活网,放松生活”>
<meta name=”author” content=”relaxlife”>
<meta name=”robots” content=”all”>
<link href=”styles.css” rel=”stylesheet” type=”text/css”>
<%
dim username
username = request.querystring(“user”)
myini = “/count/ini/” & username & “.ini”
dim fso
set fso = server.createobject(“scripting.filesystemobject”)
if fso.fileexists(server.mappath(myini)) then
’总
response.write “<br><font color=red><b>总访问量:” & getprofile(myini, “访问量”, “总访问量”) & “</b></font> <br><br>”
’年
startyear = getprofile(myini, “访问量”, “开始年”)
for i = startyear to year(date())
response.write i & “年访问量:” & getprofile(myini, “访问量”, i & “年访问量”) & “<br>”
next
response.write “<br>”
’月
startmonth = getprofile(myini, “访问量”, “开始月”)
for i = startyear to year(date())
for j = 1 to 12
if getprofile(myini, “访问量”, i & “年” & j & “月” & “访问量”) <> empty then
response.write i & “年” & j & “月” & “访问量:” & getprofile(myini, “访问量”, i & “年” & j & “月” & “访问量”) & “<br>”
end if
next
next
response.write “<br>”
response.write “<font color=red><b>今天的访问量(” & date() & “):” & getprofile(myini, “访问量”, “今天的访问量”) & “</font><br>”
response.write “昨天的访问量:” & getprofile(myini, “访问量”, “昨天的访问量”) & “<br>”
response.write “前天的访问量:” & getprofile(myini, “访问量”, “前天的访问量”) & “</b><br><br>”
response.write “<a href=manage.asp>管理个人计数器</a>”
else
response.write(“错误的参数或参数个数!!!”)
end if
set fso=nothing
%>
——————–累加器——————-
upnum.asp
<link href=”css/styles.css” rel=”stylesheet” type=”text/css”>
<!–#include file=”function.asp” –>
<%
dim username
username = request.querystring(“user”)
myini = “/count/ini/” & username & “.ini”
dim guestcli_ip
guestcli_ip=request.servervariables(“remote_addr”)
if session(“guest_ip”)=empty then
dim fso
set fso = server.createobject(“scripting.filesystemobject”)
if fso.fileexists(server.mappath(myini)) then
totalnum = getprofile(myini, “访问量”, “总访问量”) + 1
setprofile myini, “访问量”, “总访问量”, totalnum
startyearnum = getprofile(myini, “访问量”, “开始年”)
yearnum = getprofile(myini, “访问量”, year(date()) & “年访问量”)
if yearnum = empty then
setprofile myini, “访问量”, year(date()) & “年访问量”, 1
else
setprofile myini, “访问量”, year(date()) & “年访问量”, yearnum + 1
end if
monthstr = year(date()) & “年” & month(date()) & “月” & “访问量”
monthnum = getprofile(myini, “访问量”, monthstr)
if monthnum = empty then
setprofile myini, “访问量”, monthstr, 1
else
setprofile myini, “访问量”, monthstr, monthnum + 1
end if
nowday = getprofile(myini, “访问量”, “今天日期”)
ndaynum = getprofile(myini, “访问量”, “今天的访问量”)
daydate = year(date()) & “年” & month(date()) & “月” & day(date()) & “日”
if nowday = daydate then
setprofile myini, “访问量”, “今天的访问量”, ndaynum + 1
else
setprofile myini, “访问量”, “前天的访问量”, getprofile(myini, “访问量”, “昨天的访问量”)
setprofile myini, “访问量”, “昨天的访问量”, getprofile(myini, “访问量”, “今天的访问量”)
setprofile myini, “访问量”, “今天的访问量”, 1
setprofile myini, “访问量”, “今天日期”, daydate
end if
session(“guest_ip”)=guestcli_ip
else
response.write(“错误的参数或参数个数!!!”)
end if
set fso=nothing
end if
%>
&&&&&&&&&&&&&&& &&&&&&&&&&&&&&& &&用做系统设置%%%%%%%%%%%%%%%%%
iniprofile.asp
<%
rem =================================================================
rem = 函数文件:function.asp
rem = 测试文件:iniprofile.asp
rem = 说明:setprofile写入ini文件函数,getprofile读ini文件函数
rem = revision:1.01 beta
rem = 作者:熊氏英雄(cexo255)
rem = date:2005/04/22 02:00:00
rem = qq:30133499
rem = mysite:http://www.relaxlife.net
rem = 测试地址:http://www.relaxlife.net/2005/relaxlife/blogview.asp?logid=157
rem = 下载地址:http://www.relaxlife.net/2005/relaxlife/blogview.asp?logid=157
rem = qq群:4341998
rem = 适用:和delphi操作ini文件一样简单,最好是用在统计访问量,读写速度非常的快。
rem = 下版本预计改进:不能删除数据项和修改数据项,对数据的操作很全。
rem =================================================================
%>
<!–#include file=”function.asp” –>
<%
myini = “me.ini”
’实例1:操作ini文件中存在的数据项
’先定义ini文件中的数据项如下:
’[database]
’mbackcolor=-2147483643
’mforecolor=-2147483640
’mfontsize=14
’mfontname=宋体
’mheight=6450
’mleft=2310
’mtop=3195
’mwidth=10425
’ini 文件中写入数据
setprofile myini, “database”, “mbackcolor”, “-2147483643”
setprofile myini, “database”, “mforecolor”, “-2147483640”
setprofile myini, “database”, “mfontsize”, 14
setprofile myini, “database”, “mfontname”, “宋体”
setprofile myini, “database”, “mheight”, 6450
setprofile myini, “database”, “mleft”, 2310
setprofile myini, “database”, “mtop”, 3195
setprofile myini, “database”, “mwidth”, 10425
’ini 文件中读出数据并显示
mbackcolor = getprofile(myini, “database”, “mbackcolor”)
mforecolor = getprofile(myini, “database”, “mforecolor”)
mfontsize = getprofile(myini, “database”, “mfontsize”)
mfontname = getprofile(myini, “database”, “mfontname”)
mheight = getprofile(myini, “database”, “mheight”)
mtop = getprofile(myini, “database”, “mtop”)
mleft = getprofile(myini, “database”, “mleft”)
mwidth = getprofile(myini, “database”, “mwidth”)
response.write mbackcolor & “<br>”
response.write mforecolor & “<br>”
response.write mfontsize& “<br>”
response.write mfontname & “<br>”
response.write mheight & “<br>”
response.write mtop & “<br>”
response.write mleft & “<br>”
response.write mwidth & “<br>”
’实例2:操作ini文件中不存在的数据项
’ini 文件中写入数据,在此不用定义ini文件数据项
setprofile myini, “database2”, “mbackcolor2”, “-2147483643”
setprofile myini, “database2”, “mforecolor2”, “-2147483640”
’ini 文件中读出数据,在此不用定义ini文件数据项
mbackcolor2 = getprofile(myini, “database2”, “mbackcolor2”)
mforecolor2 = getprofile(myini, “database2”, “mforecolor2”)
if mbackcolor2=empty then response.write “null” else response.write mbackcolor2 & “<br>”
if mforecolor2=empty then response.write “null” else response.write mforecolor2 & “<br>”
’ini 文件中读出不存在的数据项
mbackcolor3 = getprofile(myini, “database3”, “mforecolor3”)
if mbackcolor3=empty then response.write “null” else response.write mbackcolor3 & “<br>”
%>