博文
防sql注入代码(2007-10-17 11:16:00)
摘要:safe.asp,将此文件包含到每页的顶部,下面就正常使用request,或request.querystring来获取传过来的值了,不需要检测了,因为已经检测过了。<%Sql_in="and |or |on |in |select |insert |update |delete |exec |declare |'" '防止GET方法--------------------------------------------------------------------------------- '区分出注入字符 Sql=Split(Sql_in,"|") '如果GET过来的数据不为空 If Request.QueryString<>"" Then '逐一取出提交过来的参数 For Each Sql_Get In Request.QueryString For Sql_Data=0 To Ubound(Sql) '判断是否包含非法字符 IF Instr(Lcase(Request.QueryString(Sql_Get)),Sql(Sql_Data))<>0 Then '如果有非法字符,弹出对话框提示,并自动返回上一页 Response.Write("<script>alert('系统提示:请不要输入非法字符尝试注入↓,你的IP已记录!');history.go(-1);</script>") Response.End() End IF Next Next End If '防止POST方法------......
asp连接远程mssql数据库代码(2007-09-19 10:00:00)
摘要:当远程MSSQL数据库更改了端口号,所以连接的代码也要相应的改一下<%dim conn,connstrset conn = server.createobject("adodb.connection")connstr="Provider=sqloledb;Data Source=*.*.*.*,端口号;Network Library=DBMSSOCN;Initial Catalog=数据库名;User ID=用户名;Password=密码;" conn.open connstr%>......
fso检测文件、磁盘、文件夹是否存在代码(2007-09-15 22:43:00)
摘要:利用FSO检测文件、磁盘、文件夹是否存在<% dim fso set fso=server.createobject("scripting.filesystemobject") if fso.driveexists("d:") then response.write"磁盘D是存在的" else response.write"磁盘D是不存在的" end if
if fso.folderexists(server.mappath("folder")) then response.write"folder文件夹是存在的" else response.write"folder文件夹是不存在的" end if
if fso.fileexists(server.mappath("sss.ASP")) then response.erite"sss.asp文件是存在的" else response.write"sss.asp文件是不存的" end if
set fso=nothing %> ......
网页颜色对话框的使用(2007-09-06 15:25:00)
摘要:index.asp页面的内容<script language='JavaScript'>function SelectColor(sEL,form){ var dEL = document.all(sEL); var url = 'selcolor.asp?color='+encodeURIComponent(sEL); var arr = showModalDialog(url,window,'dialogWidth:280px;dialogHeight:250px;help:no;scroll:no;status:no'); if (arr) { form.value=arr; //sEL.style.backgroundColor=arr; }}</script><form name="form1" method="post" action=""> <input name='FontColor' type='text' value='' size='10' maxlength='10'><a href="#" onclick="SelectColor(this,FontColor)">选择颜色</a></form>selcolor.asp页面内容<HTML><HEAD><META content="text/html; charset=gb2312" http-equiv="Content-Type">
<STYLE type=text/css>TD {FONT-SIZE: 10.8pt}BODY {FONT-SIZE: 10.8pt}BUTTON {WIDTH: 5em}</STYLE>
<SCRIPT language=JavaScrip......
asp随机获取数据库中的记录代码(2007-08-30 12:29:00)
摘要:利用asp随机获取数据库中的记录且不出现重复的记录<!--#include file="adoconn.asp"--><%'-------------------------检索数据-----------------------strSQL = "SELECT * FROM [table]" 'Sql语句,检索数据库'Set objRS = Server.CreateObject("ADODB.Recordset") '创建记录集rs.Open strSQL,conn,1,1 '执行检索Count=rs.RecordCount '得到记录总数Item=2 '显示记录数'-------------------------检索数据-----------------------
'-------------------------------------------------------------------------------redim a(Item, 3),t(Count)'定义2数组,数组a用来储存记录,数组t用来删选记录
'-----------------------------------......
生成静态页面方法二(2007-08-17 15:11:00)
摘要:原理:用asp获取动态页面的html代码后,再将这些html代码写成html代码。<%Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")path=server.mappath("index.html")If Myfileobject.fileexists(path) Then '如果存在此文件,删除之 MyfileObject.deletefile pathEnd IfSet MyTextFile=MyFileObject.CreateTextFile(path)strurl="http://www.sina.com.cn/" '这里可以换成其他动态页面的地址。strTmp = GetHTTPPage(trim(strurl))
MyTextFile.WriteLine(strTmp)
MytextFile.Closeresponse.write "完成任务"%>
<%Function getHTTPPage(url) On Error Resume Next dim http set http=Server.createobject("Microsoft.XMLHTTP") Http.open "GET",url,false Http.send() if Http.readystate<>4 then exit function end if getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312") set http=nothing If Err.number<>0 then Response.Write "<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>" Err.Clear End If End Fu......
ASP备份和恢复MSSQL数据库的操作方法(2007-08-16 08:48:00)
摘要:利用asp实现对mssql数据库的备份和恢复。1、备份 <% SQL="backup database 数据库名 to disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'" set cnn=Server.createobject("adodb.connection") cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=" cnn.execute SQL on error resume next if err<>0 then response.write "错误:"&err.Descripting else response.write "数据备份成功!" end if %> 2、恢复 <% SQL="Restore database 数据库名 from disk='"&Server.MapPath("backup")&"\"&"backuptext.dat"&"'" set cnn=Server.createobject("adodb.connection") cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd=" cnn.execute SQL on error resume next if err<>0 then response.write "错误:"&err.Descripting else response.write "数据恢复成功!" end if %>......
asp天气预报采集代码(2007-08-07 13:49:00)
摘要:<%'此程序用来获取北京的天气预报,可以将北京换成你想要的地点。strurl="http://weather.tq121.com.cn/mapanel/index1.php?city=北京"s1="<table width=""166"" height=""15"" border=""0"" cellpadding=""0"" cellspacing=""0"">"s2="<table width=""169"" height=""37"" border=""0"" cellpadding=""0"" cellspacing=""5"">" Dim j1,l,b(3) strTmp = GetHTTPPage(strurl) wstr=strCut(strTmp, s1,s2,2) ' wstr=Replace(s1&wstr,"<br>","|") wstr=Replace(wstr,"</table>","</table>|") wstr=RemoveHTML(wstr) wstr=Replace(wstr,Chr(10),"") wstr=Replace(wstr,Chr(32),"") wstr=Replace(wstr," ","") str=Split(wstr,"|") For i=0 To 3 response.write str(i)&"<br>" nextresponse.End%><%Function regExReplace(sSource,patrn, replStr) Dim regEx, str1 str1 = sSource Set regEx = New RegExp regEx.Pattern = patrn regEx.IgnoreCase = True regEx.Global = True regExReplace = regEx.Replace(str1, r......
利用fso显示某一文件夹中的所有内容(2007-08-01 09:41:00)
摘要:利用fso显示某一文件夹中的所有内容<%'创建一个FileSystemObject对象的事例Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")path=server.mappath("./folder") '当前目录下folder文件夹目录'创建一个Folder对象Set MyFolder=MyFileObject.GetFolder(path)For Each thing in MyFolder.SubFolders '获取子文件夹 response.write "<p>目录:"&thing' MyFileObject.DeleteFolder thing 删除文件夹,注意使用next '循环显示其中文件For Each thing in MyFolder.FilesResponse.Write("<p>文件:"&thing) '输出文件路径'MyFileObject.DeleteFile thing '删除这些文件,此删除不可以恢复,需要小心使用Next%>......
ASPJPEG组件使用说明(2007-07-27 09:15:00)
摘要:利用aspjpeg组件对图片进行处理
1、为图片制作缩略图
<% ' 建立实例Dim Jpeg,PathSet Jpeg = Server.CreateObject("Persits.Jpeg")' 图片所在位置Path = Server.MapPath("images") & "\clock.jpg"
' 打开Jpeg.Open Path
' 设置缩略图大小(这里比例设定为50%)Jpeg.Width = Jpeg.OriginalWidth / 2Jpeg.Height = Jpeg.OriginalHeight / 2
' 保存缩略图到指定文件夹下Jpeg.Save Server.MapPath("images") & "\clock_small.jpg"
' 注销实例Set Jpeg = Nothing%>
<IMG SRC="images/clock.jpg"><P><IMG SRC="images/clock_small.jpg">
2、为图片加入水印功能
<%Dim Jpeg' 建立实例Set Jpeg = Server.CreateObject("Persits.Jpeg")' 打开目标图片Jpeg.Open Server.MapPath("images/dodge_viper.jpg")
' 添加文字水印Jpeg.Canvas.Font.Color = &HFF0000' 红色Jpeg.Canvas.Font.Family = "宋体"Jpeg.Canvas.Font.Bold = True Jpeg.Canvas.Print 10, 10, "Copyright (c) Cnmaya.org"
' 保存文件Jpeg.Save Server.MapPath("images/dodge_viper_framed.jpg")
' 注销对象Set Jpeg = Nothing%>
' Aspjpeg 功能设置Set Jpeg = Server.CreateObject("Persits.Jpeg")' 获取源图片路径Path = Server.MapPath("uploadimages/")&"/"&Fil......
