ASP中将web页面另存为EXCEL文档简单易用的新方法

Filed Under (ASP茶座) by 有为 on 16-04-2010

<% Response.Buffer  =  TRUE
Response.AddHeader “Content-Disposition”,”attachment:filename=查询报表”&replace(now(),”:”, “-”)& “rxx “”.xls”
Response.contentType= “application/vnd.ms-excel”
%>

当页面存在数字时,导出EXCEL就变为科学记数法的形式,要使数字正常显示,请尝试下面办法。

“首先,我们了解一下excel从web页面上导出的原理。当我们把这些数据发送到客户端时,我们想让客户端程序(浏览器)以excel的格式读取它,所以把mime类型设为:application/vnd.ms-excel,当excel读取文件时会以每个cell的格式呈现数据,如果cell没有规定的格式,则excel会以默认的格式去呈现该cell的数据。这样就给我们提供了自定义数据格式的空间,当然我们必须使用excel支持的格式。下面就列出常用的一些格式:
1) 文本:vnd.ms-excel.numberformat:@
2) 日期:vnd.ms-excel.numberformat:yyyy/mm/dd
3) 数字:vnd.ms-excel.numberformat:#,##0.00
4) 货币:vnd.ms-excel.numberformat:¥#,##0.00
5) 百分比:vnd.ms-excel.numberformat: #0.00%
这些格式你也可以自定义,比如年月你可以定义为:yy-mm等等。那么知道了这些格式,怎么去把这些格式添加到cell中呢?很简单,我们只需要把样式添加到对应的标签对(即闭合标签)即可。如<td></td>,给标签对<td></td>添加样式,如下: <td style=”vnd.ms-excel.numberformat:@”>410522198402161833</td>
同样,我们也可以给<div></div>添加样式,也可以给<tr>< /tr>,<table></table>添加样式;当我们在父标签对和子标签对都添加样式时,数据会以哪一个样式呈现呢?经过测试,会以离数据最近的样式呈现.

无组件上传中禁止ASP木马上传代码,ASP下测试通过(原创)

Filed Under (ASP茶座) by 有为 on 03-09-2009

Function CheckASP(Byval sFileName)
dim FStream,stamp,sData
Set FStream=Server.createobject(”ADODB.Stream”)
FStream.Open
FStream.Type=1
FStream.LoadFromFile sFileName
FStream.position=0
stamp=FStream.read
sData = ByteArray2Text( stamp )
If SniffHtml( sData ) Then
FStream.Close
Set FStream=nothing
CheckASP = true
EXIT Function
End If
If SniffASP( sData ) Then
FStream.Close
Set FStream=nothing
CheckASP = true
EXIT Function
End If
FStream.Close
Set FStream=nothing
If err.number<>0 then return = true
CheckASP = false
End Function

Private Function SniffHtml( sData )

Dim oRE
Set oRE = New RegExp
oRE.IgnoreCase    = True
oRE.Global        = True

Dim aPatterns
aPatterns = Array( “<!DOCTYPE\W*X?HTML”, “<(body|head|html|img|pre|script|table|title)”, “type\s*=\s*[\'""]?\s*(?:\w*/)?(?:ecma|java)”, “(?:href|src|data)\s*=\s*[\'""]?\s*(?:ecma|java)script:”, “url\s*\(\s*[\'""]?\s*(?:ecma|java)script:” )

Dim i
For i = 0 to UBound( aPatterns )
oRE.Pattern = aPatterns( i )
If oRE.Test( sData ) Then
SniffHtml = True
Exit Function
End If
Next

SniffHtml = False

End Function

Private Function SniffASP( sData )
Dim oRE
Set oRE = New RegExp
oRE.IgnoreCase = True
oRE.Global  = True

Dim aPatterns
aPatterns = Array(”.(getfolder|createfolder|deletefolder|createdirectory|deletedirectory|saveas)”,”wscript.shell”,”script.encode”,”server.”,”.createobject”,”execute”,”activexobject”,”language=”,”request”,”server”,”script”)
Dim i
For i = 0 to UBound( aPatterns )
oRE.Pattern = aPatterns( i )
If oRE.Test( sData ) Then
SniffASP = true
Exit Function
End If
Next
SniffASP = false
End Function

Private Function ByteArray2Text(varByteArray)
Dim strData, strBuffer, lngCounter
strData = “”
strBuffer = “”
For lngCounter = 0 to UBound(varByteArray)
strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
‘Keep strBuffer at 1k bytes maximum
If lngCounter Mod 1024 = 0 Then
strData = strData & strBuffer
strBuffer = “”
End If
Next
ByteArray2Text = strData & strBuffer
End Function

修补upfile.asp上传漏洞

Filed Under (ASP茶座) by 有为 on 29-07-2009

ASP文件相关的一些函数。有以下几个:
1. 得到文件扩展名
2. ASP上传文件漏洞检测
3. 格式化显示文件大小
4. asp检测上传图片是否为真实图片
5. 上传文件扩展名检测
6. 取得文件对应的图标
7. 下载文件等相关函数

程序代码:
<%
‘*******************************************************
‘作    用: 得到文件扩展名
‘函数名: GetFileExt(fileTrue)
‘参    数: sFileName 文件名
‘返回值: 返回文件扩展名
‘*******************************************************
function GetFileExt(sFileName)
GetFileExt = UCase(Mid(sFileName,InStrRev (sFileName, “.”)+1))      ‘下面有附
End function

‘*******************************************************
‘作    用: ASP上传漏洞 “\0″ 防范
‘函数名: TrueStr(fileTrue)
‘参    数: sFileName 文件名
‘返回值: 合法文件返回 True ,否则返回False
‘*******************************************************
function IsTrueFileName(sFileName)
dim str_len,pos
str_len=len(sFileName)
pos=Instr(sFileName,chr(0))
If pos=0 or pos=str_len then
IsTrueFileName = true
else
IsTrueFileName = false
End If
End function « 阅读全文 »

[asp编程]asp获取用户浏览器类型及操作系统版本的函数

Filed Under (ASP茶座) by 有为 on 08-12-2008

Function SystemCheck()
useragent=Request.ServerVariables(”HTTP_USER_AGENT”)
‘转化为小写
useragent=Lcase(useragent)

‘Browser Check
dim btype,bname,bversion,idx,Os
btype=”"
if inStr(useragent,”icab”) then
bname=”iCab”
elseif inStr(useragent,”lynx”) then
bname=”Lynx”
elseif inStr(useragent,”links”) then
bname=”Links”
elseif inStr(useragent,”elinks”) then
bname=”ELinks”
elseif inStr(useragent,”jbrowser”) then
bname=”JBrowser”
elseif inStr(useragent,”konqueror”) then
bname=”Konqueror”
elseif inStr(useragent,”gecko”) then
bname=”Mozilla”
btype=btype &”[Gecko]”
if inStr(useragent,”aol”) then
bname=”AOL”
elseif inStr(useragent,”netscape”) then
bname=”Netscape”
elseif inStr(useragent,”firefox”) then
bname=”FireFox”
elseif inStr(useragent,”chimera”) then
bname=”Chimera”
elseif inStr(useragent,”camino”) then
bname=”Camino”
elseif inStr(useragent,”galeon”) then
bname=”Galeon”
elseif inStr(useragent,”k-meleon”) then
bname=”K-Meleon”
end if
elseif inStr(useragent,”bot”) or inStr(useragent,”crawl”) or inStr(useragent,”spider”) or inStr(useragent,”mediapartners”) or inStr(useragent,”slurp”) then
btype=btype &”[Bot/Crawler/Spider]”
if inStr(useragent,”grub”) then
bname=”Grub”
elseif inStr(useragent,”googlebot”) or inStr(useragent,”google”) then
bname=”GoogleBot”
elseif inStr(useragent,”baidu”) then
bname=”BaiduBot”
elseif inStr(useragent,”sogou”) then
bname=”SogouBot”
elseif inStr(useragent,”msnbot”) then
bname=”MSN Bot”
elseif inStr(useragent,”slurp”) then
bname=”Yahoo! Slurp”
end if
elseif inStr(useragent,”wget”) then
bname=”Wget”
elseif inStr(useragent,”ask jeeves”) or inStr(useragent,”teoma”) then
bname=”Ask Jeeves/Teoma”
elseif inStr(useragent,”msie”) then
btype=”[IE"
bversion=Mid(useragent,inStr(useragent,"msie")+5,3)
btype=btype & bversion &"]”
bname=”IE”
if inStr(useragent,”msn”) then
bname=”MSN”
elseif inStr(useragent,”aol”) then
bname=”AOL”
elseif inStr(useragent,”webtv”) then
bname=”WebTV”
elseif inStr(useragent,”myie2″) then
bname=”MyIE2″
elseif inStr(useragent,”maxthon”) then
bname=”Maxthon”
elseif inStr(useragent,”gosurf”) then
bname=”GoSurf”
elseif inStr(useragent,”netcaptor”) then
bname=”NetCaptor”
elseif inStr(useragent,”sleipnir”) then
bname=”Sleipnir”
elseif inStr(useragent,”avant browser”) then
bname=”AvantBrowser”
elseif inStr(useragent,”greenbrowser”) then
bname=”GreenBrowser”
elseif inStr(useragent,”slimbrowser”) then
bname=”SlimBrowser”
end if
elseif inStr(useragent,”opera”) then
bname=”Opera”
idx=inStr(useragent,”opera”)
bversion=mid(useragent,idx+6,idx+9)
bname=bname & bversion
elseif inStr(useragent,”applewebkit”) then
btype=”[AppleWebKit]”
if inStr(useragent,”omniweb”) then
bname=”OmniWeb”
elseif inStr(useragent,”safari”) then
bname=”Safari”
elseif inStr(useragent,”mozilla”) then
bname=”Mozilla”
end if
end if

‘Os Check
if inStr(useragent,”windows ce”) then
Os=”Windows ce”
elseif inStr(useragent,”windows 95″) then
Os=”Windows 95″
elseif inStr(useragent,”windows 98″) then
Os=”Windows 98″
elseif inStr(useragent,”windows 2000″) then
Os=”Windows 2000″
elseif inStr(useragent,”windows xp”) then
Os=”Windows XP”
elseif inStr(useragent,”windows nt 5.0″) then
Os=”Windows 2000″
elseif inStr(useragent,”windows nt 5.1″) then
Os=”Windows XP”
elseif inStr(useragent,”windows nt 5.2″) then
Os=”Windows 2003″
elseif inStr(useragent,”windows nt”) then
Os=”Windows NT”
elseif inStr(useragent,”win32″) then
Os=”Win32″
elseif inStr(useragent,”x11″) or inStr(useragent,”unix”) then
Os=”unix”
elseif inStr(useragent,”sunos”) or inStr(useragent,”sun os”) then
Os=”SUN OS”
elseif inStr(useragent,”powerpc”) or inStr(useragent,”ppc”) then
Os=”PowerPC”
elseif inStr(useragent,”macintosh”) then
Os=”Mac”
elseif inStr(useragent,”mac osx”) then
Os=”MacOSX”
elseif inStr(useragent,”freebsd”) then
Os=”FreeBSD”
elseif inStr(useragent,”linux”) then
Os=”Linux”
elseif inStr(useragent,”palmsource”) or inStr(useragent,”palmos”) then
Os=”PalmOS”
elseif inStr(useragent,”wap “) then
Os=”WAP”
end if

if bname=”" then bname=”unknow”
if Os=”" then Os=”unknow”

SystemCheck=bname & btype & “/” &Os
end Function
‘+++++++++++结束+++++++++++

ASP无组件上传后乱码问题(解决)

Filed Under (ASP茶座) by 有为 on 25-09-2008

UTF-8转换为GB2312编码的方法

第一步:修改 连接数据库文件
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<%
Option Explicit
Response.Buffer = True
Server.ScriptTimeOut = 90
Session.CodePage=936
%>
参考的是:
如果制作的网页脚本与WEB服务端的默认代码页不同,则必须指明代码页:
codepage=936 简体中文GBK
codepage=950 繁体中文BIG5
codepage=437 美国/加拿大英语
codepage=932 日文
codepage=949 韩文
codepage=866 俄文
codepage=65001 unicode UFT-8 « 阅读全文 »