选择显示字体大小

一个比较实用的asp函数集合类(2)

     '******************************
   '名称: chkinvstr
   '参数:str
   '返回值:true/false
   '创建时间:2005年5月2日
   '作用:检查参数是否有非法字符
   '******************************
   public function chkinvstr(str)
   rem 定义需要过滤得非法字符
   dim invaildword,inwords,i
   str=cstr(str)
   chkinvstr=false
   if len(replace(p_invaildwords,chr(0),""))<1 then
   adderrorcode(103) 'invaildwords is null
   exit function
   else
   if instr(1,p_invaildwords,"")>0 then
   invaildword=split(p_invaildwords,"")
   inwords=lcase(trim(str))
   for i=lbound(invaildword) to ubound(invaildword)
   if instr(inwords,invaildword(i))>0 then
   p_error=1982
   adderrorcode(105)
   chkinvstr=true
   exit function
   end if
   next
   else
   adderrorcode(104) '"" is requried.
   exit function
   end if
   end if
   end function
  
   '******************************
   '名称: getip
   '参数:null
   '返回值:null
   '创建时间:2005年5月3日
   '作用:得到用户的ip地址
   '******************************
   public function getip()
   p_ipadd=request.servervariables("http_x_forwarded_for")
   if isnull(p_ipadd) or p_ipadd="" then
   p_ipadd=request.servervariables("remote_addr")
   end if
   getip=p_ipadd
   end function
  
   '******************************
   '名称: ipaddress
   '参数:sip
   '返回值:county,city
   '作用:对数据内容进行排版转换
   '创建时间:2005年5月6日
   '来源:www.knowsky.com
   '******************************
   public function ipaddress(sip)
   dim ipconnstr,ipconn,ipaddressdb
   dim str1,str2,str3,str4
   dim num
   dim country,city,address
   dim iprs,sql
   address="未知"
   if isnumeric(left(sip,2)) then
   if sip="127.0.0.1" then sip="192.168.0.1"
   str1=left(sip,instr(sip,".")-1)
   sip=mid(sip,instr(sip,".")+1)
   str2=left(sip,instr(sip,".")-1)
   sip=mid(sip,instr(sip,".")+1)
   str3=left(sip,instr(sip,".")-1)
   str4=mid(sip,instr(sip,".")+1)
   if isnumeric(str1)=0 or isnumeric(str2)=0 or isnumeric(str3)=0 or isnumeric(str4)=0 then
   else
   num=clng(str1)*16777216+clng(str2)*65536+clng(str3)*256+clng(str4)-1
   ipaddressdb = "dsj_ipaddress.mdb"
   ipconnstr = "provider = microsoft.jet.oledb.4.0;data source = " & server.mappath(p_dbfolder & ipaddressdb)
   set ipconn = server.createobject("adodb.connection")
   ipconn.open ipconnstr
   country="亚洲"
   city=""
   sql="select top 1 country,city from dsj_ipaddress where ip1 <="&num&" and ip2 >="&num&""
   set iprs=ipconn.execute(sql)
   if not(iprs.eof and iprs.bof) then
   country=iprs(0)
   city=iprs(1)
   end if
   iprs.close:set iprs=nothing
   ipconn.close:set ipconn = nothing
   sqlquerynum = sqlquerynum+1
   end if
   ipaddress=country&city
   end if
   end function
  
   '******************************
   '名称: clientconnected
   '参数:null
   '返回值:null
   '创建时间:2005年5月5日
   '作用:得到用户是否与服务器连接
   '******************************
   public sub clientconnected()
   if response.isclientconnected then
   response.flush()
   else
   response.end()
   end if
   end sub
  
   '******************************
   '名称: chkpost
   '参数:null
   '返回值:true/false
   '创建时间:2005年5月5日
   '作用:检查被提交的数据来源
   '******************************
   public function chkpost()
   dim server_v1,server_v2
   chkpost=false
   server_v1=cstr(request.servervariables("http_referer"))
   server_v2=cstr(request.servervariables("server_name"))
   if mid(server_v1,8,len(server_v2))=server_v2 then chkpost=true
   end function
  
   '******************************
   '名称: adderrorcode
   '参数:errcode
   '返回值:errcodes
   '创建时间:2005年5月3日
   '作用:添加错误代码到errcodes中
   '******************************
   public sub adderrorcode(errcode)
   if errcodes="" then
   errcodes=errcode
   else
   errcodes=errcodes & "," & errcode
   end if
   end sub
  
   '******************************
   '名称: showerrmsg
   '参数:null
   '返回值:null
   '创建时间:2005年5月3日
   '作用:显示详细的错误信息
   '******************************
   public function showerrmsg()
   if not p_debug then on error resume next
   if errcodes<>"" then
   ierrcodes=split(errcodes,",",-1,binary)
   for i=lbound(ierrcodes) to ubound(ierrcodes)
   tmperrcode=clng(ierrcodes(i))
   if isnumeric(tmperrcode) then
   errmsg=errmsg & errdetails(tmperrcode)
   end if
   next
   end if
   showerrmsg=errmsg
   end function
  
   '******************************
   '名称: connectiondatabase
   '参数:database,p_dbuserid,p_dbpassword,p_dbtype
   '返回值:null
   '作用:连接到数据库
   '创建时间:2005年5月6日
   '******************************
   public function connectiondatabase(param_database,param_dbuserid,param_dbpassword,param_dbtype)
   if not p_debug then on error resume next
   clientconnected
   if isnumeric(param_dbtype) then
   set objconn=server.createobject("adodb.connection")
   objconn.connectiontimeout=10 '设置连接超时为10秒
   dbpath=server.mappath(p_dbfolder&param_database)
   'response.write dbpath
   select case param_dbtype
   case 11: 'access data base(oledb)
   connstr="provider=microsoft.jet.oledb.4.0;data source="&dbpath&";user id="&param_dbuserid&";password="&param_dbpassword&""
   case 21: 'sql server (oledb)
   connstr="provider=sqloledb;initial catalog="&param_database&";data source="&p_sqldatasource&";user id="&param_dbuserid&";password="&param_dbpassword&""
   case 12: 'access data base(odbc)
   connstr="driver={microsoft access driver (*.mdb)};dbq="&dbpath&";user id="&param_dbuserid&";password="&param_dbpassword
   case 22: 'sql server (odbc)
   connstr="driver={sql server};database="&param_database&";server="&p_sqldatasource&";user id="&param_dbuserid&";password="&param_dbpassword&""
   case else:
   adderrorcode(100)
   if p_debug then response.write showerrmsg()
   'exit function
   end select
   objconn.connectionstring=connstr
   objconn.open
   set connectiondatabase=objconn
   if err then
   err.clear
  
   if savelog then
   tmpmsg="数据库连接时出现错误,请检查您的查询代码是否正确。<br>基于安全的理由,只显示本信息,要查看详细的错误信息,请设置dsj.debug=true"
   cmd="execute the command of :"&param_dbtype
   response.write savesqllog(cmd,tmpmsg)
   else
   response.write "数据库连接时出现错误,请检查您的查询代码是否正确。"
   end if
   adderrorcode(101)
   set objconn=nothing
   response.end()
   end if
   end if
   end function
  
   '******************************
   '名称: savesqllog
   '参数:scommand,msg
   '返回值:msg
   '作用:存储日志
   '创建时间:2005年5月6日
   '******************************
   public function savesqllog(scommand,msg)
   if not p_debug then on error resume next
   logdb="dsj_sqllog.mdb"
   'connectiondatabase logdb,p_dbuserid,p_dbpassword,12
   logconnstr = "provider = microsoft.jet.oledb.4.0;data source = " & server.mappath(p_dbfolder & logdb)
   set logconn = server.createobject("adodb.connection")
   logconn.open logconnstr
   if savelog then
   dim logcmd
   logcmd="insert into dsj_sql_log (command,scriptname,loguser,ip) values "
   logcmd=logcmd & "('" & replace(left(scommand,255),"'","''") &"','" & (scriptfolder & scriptname) &"','" & session("user") & "','"& getip & "')"
   'response.write "need to execute command is:<br><font color=red>" & logcmd & "</font><br>"
   logconn.execute(logcmd)
   end if
   logconn.close
   set logconn=nothing
   savesqllog=msg
   sqlquerynum=sqlquerynum+1
   end function
  
   '******************************
   '名称: executecmd
   '参数:cmd
   '返回值:recordset
   '作用:返回由cmd创建的记录集
   '创建时间:2005年5月6日
   '******************************
   public function executecmd(cmd)
   if not isobject(objconn) then connectiondatabase p_database,p_dbuserid,p_dbpassword,p_dbtype
   if not p_debug then on error resume next
   clientconnected
   set executecmd=objconn.execute(cmd)
   if err then
   err.clear
   objconn.close
   set objconn=nothing
   if savelog then
   tmpmsg="查询数据的时候发现错误,请检查您的查询代码是否正确。<br>基于安全的理由,只显示本信息,要查看详细的错误信息,请设置dsj.debug=true"
   response.write savesqllog(cmd,tmpmsg)
   else
   response.write "查询数据的时候发现错误,请检查您的查询代码是否正确。"
   end if
   response.end()
   end if
   sqlquerynum=sqlquerynum+1
   end function
  
   '******************************
   '名称: htmlencode
   '参数:fstring
   '返回值:htmlencode
   '作用:对数据内容进行排版转换
   '创建时间:2005年5月6日
   '******************************
   public function htmlencode(fstring)
   if not isnull(fstring) or fstring<>"" then
   fstring=replace(fstring,"<","<")
   fstring=replace(fstring,">",">")
   fstring=replace(fstring,chr(9)," ") '倾斜字体
   fstring=replace(fstring,chr(13),"")
   fstring=replace(fstring,chr(32)," ") '转换空格
   fstring=replace(fstring,chr(34),"&quot;") '转换双引号
   fstring=replace(fstring,chr(39),"&#39;") '转换单引号
   fstring=replace(fstring,chr(10),"</p><p>") '转换成段落格式
   fstring=replace(fstring,chr(10),"<br>    ") '转换为下一行
   fstring=replace(fstring,chr(13),"<br>")
   fstring=replace(fsting,vbcrlf,"<br>")
   'fstring=linkfriend(fstring)
   'fstring=chkbadwords(fstring)
   htmlencode=fstring
   end if
   end function
  
   '******************************
   '名称: linkfriend
   '参数:fcontent
   '返回值:linkfriend
   '作用:进行友情连接替换
   '创建时间:2005年5月6日
   '******************************
   public function linkfriend(fcontent)
   if not p_debug then on error resume next
   if not isobject(objconn) then connectiondatabase database,dbuserid,dbpassword,dbtype
   set rsfriend=executecmd("select title,url from dsj_friendlink")
   if rsfriend.eof and rsfriend.bof then
   else
   do while not rsfriend.eof
   strtitle=rsfriend.fields.item("title")
   url=rsfriend.fields.item("url")
   if lcase(left(url,1))<>"h" then url=replace(url,left(url,1),"")
   strlink="<a target='_blank' title='" & strtitle &"' href='" & url & "'>"
   strlink=strlink&strtitle&"</a>"
   if instr(fcontent,strtitle)>0 then fcontent=replace(fcontent,strtitle,strlink)
   rsfriend.movenext
   loop
   linkfriend=fcontent
   end if
   rsfriend.close
   set rsfriend=nothing
   sqlquerynum=sqlquerynum+1
   end function
  
   '***************************************************************
   '名称: showpage
   '参数:null
   '返回值:null
   '作用:显示经过分页后的记录导航
   '说明:
   ' 原作:zykj2000 网站:http://bbs.513soft.net
   ' 修改:孤剑 网站:http://blog.csdn.net/alonesword/
   '时间:2005年5月7日
   '******************************************************************
   public sub showpage()
   dim str_tmp
   p_inttotalrecords=rsdivpage.recordcount
   if p_inttotalrecords<=0 then
   p_error=p_error & "总记录数为零,请输入数据"
   call showerror()
   end if
   if p_inttotalrecords <=pagesize then
   p_inttotalpage=1
   else
   if p_inttotalrecords mod pagesize =0 then
   p_inttotalpage = clng(p_inttotalrecords / pagesize * -1)*-1
   else
   p_inttotalpage = clng(p_inttotalrecords / pagesize * -1)*-1+1
   end if
   end if
   if p_intcurpage>p_inttotalpage then
   p_intcurpage=p_inttotalpage
   end if
   response.write showfirstprv
   shownumbtn
   response.write shownextlast&" "
   response.write showpageinfo
   response.write str_tmp
   end sub
  
   private function showfirstprv()
   dim str_tmp,int_prvpage
   int_prvpage=p_intcurpage-1
   if int_prvpage<1 then int_prvpage=1
   btn_firstlink="<a title='第1页' href='"&addnpageurl&"1'>"&btn_first
   btn_prevlink="<a title='第"&int_prvpage&"页' href='"&addnpageurl&p_intcurpage-1&"'>"&btn_prev
   if p_intcurpage=1 then
   str_tmp=btn_firstlink&"</a> "&btn_prevlink&"</a> "
   else
   int_prvpage=p_intcurpage-1
   str_tmp=""&btn_firstlink&"</a> "& btn_prevlink&"</a> "
   end if
   showfirstprv=str_tmp
   end function
  
   private function shownextlast()
   dim str_tmp,int_nextpage
   int_nextpage=p_intcurpage+1
   if p_intcurpage+1>p_inttotalpage then int_nextpage=p_inttotalpage
   btn_nextlink="<a title='第"&int_nextpage&"页' href='"&addnpageurl&p_intcurpage+1&"'>"&btn_next
   btn_lastlink="<a title='第"&p_inttotalpage&"页' href='"&addnpageurl&p_inttotalpage&"'>"&btn_last
   if p_intcurpage>=p_inttotalpage then
   str_tmp=btn_nextlink & "</a> " & btn_lastlink&"</a>"
   else
   int_nextpage=p_intcurpage+1
   str_tmp=""&btn_nextlink&"</a> "& btn_lastlink&"</a>"
   end if
   shownextlast=str_tmp
   end function
  
   private function shownumbtn()
   dim i,str_tmp
   dim pagelink
   str_tmp=""
   for i=1 to p_inttotalpage step 1
   pagelink=" <a title='第"&i&"页' href='"&addnpageurl&i&"'>"&i&"</a> "
   if i=p_intcurpage then pagelink=" <a title='第"&i&"页' href='"&addnpageurl&i&"'><font color=red>"&i&"</font></a> "
   response.write pagelink
   next
   shownumbtn=str_tmp
   end function
  
   private function showpageinfo()
   dim str_tmp
   str_tmp="页次:"&p_intcurpage&"/"&p_inttotalpage&"页 共"&p_inttotalrecords&"条记录 "&p_rspagesize&"条/每页"
   showpageinfo=str_tmp
   end function
  
   private function addnpageurl()
   dim i,j,search_str,result_url
   search_str="page="
   str_params=request.servervariables("query_string")
   if str_params="" then
   result_url=scriptname & "?page="
   else
   if instrrev(str_params,search_str)=0 then
   result_url=scriptname & "?" & str_params &"&page="
   else
   j=instrrev(str_params,search_str)-2
   if j=-1 then
   result_url=scriptname & "?page="
   else
   str_params=left(str_params,j)
   result_url=scriptname & "?" & str_params &"&page="
   end if
   end if
   end if
   addnpageurl=result_url
   end function
   '******************************************************************
   public function getname(options)
   dim tmpname
   tmpname=request.servervariables("path_info")
   arrtmpname=split(tmpname,"/")
   if options=0 then getname=server.mappath(".")&getname(1)
   if options=1 then getname=lcase(arrtmpname(ubound(arrtmpname)))
   if options=2 then getname=lcase(arrtmpname(ubound(arrtmpname)-1))&"/"
   end function
  
  end class
  %>
  
    


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons