Archive for the ‘ASP编程’ Category

海阳2006 功能中的潜水王

星期一, 06月 2nd, 2008

ps:我还没测试.
信息来源:H4×0r’s Blog
[复制此相关代码]CODE:
bOtherUser = False ”是否需要其它NT用户身份登录
If bOtherUser = True And Trim(Request.ServerVariables(”AUTH_USER”)) = “” Then
Response.Status = “401 Unauthorized”
Response.Addheader “WWW-AuThenticate”, “BASIC”
If Request.ServerVariables(”AUTH_USER”) = “” Then Response.End()
End If

重点点播
Response.Status = “401 Unauthorized”只要在相关代码开头加入这句,IIS就会自动调用登陆窗口啦
此功能可以调用其它NT用户身份登录
如果您知道比GUEST权限大de用户de密码什么de话,比如管理员,嘿嘿~您就发达了[例如:通过FINDPASS,或自动登陆获取de]
比如知道管理员de密码,但是对方没终端,没其他可以提权限de东东,嘿嘿这个东西就可以帮您忙了
登陆后,获得de权限是相应de登陆用户de权限哦!
敏感目录:存放CIFdePCANYWHERE、启动等目录
可以进入该用户拥有权限de所有目录,以及查阅其拥有权限de文件,比如LOG什么de.

ASP javascript Application对象的Contents和StaticObjects做Cache的一些经验

星期一, 06月 2nd, 2008

Application对象内置集合有为存放简单类型设计deContents,默认Application(”key”)就可以使用.
不过Application.Contents不能存放对象,可以存vbs数组,但是在javascript下甚至数组都不能放.
使用Application.Contents时,只能用丑陋de如:
for(var i=0;i<15000;i ){
Application.Lock();
// Application.Contents(i)=”sdfdsffdsaf”;
Application(i)=”sdfdsffdsaf”;
Application.Unlock();}
在这里往Application.Contents存放了1.5w个String,共花费时间234ms.
改用Application.StaticObjects后:
定义一个Dictionary作为StaticObject,用于存放数据,因为StaticObject是不允许直接访问de.
<object id=”dict” runat=”server” scope=”Application” progid=”Scripting.Dictionary”></object>
Scripting.Dictionary本身de速度很快,不会对比较StaticObjects集合速度造成太大影响.
Dictionaryde速度:
var d=new ActiveXObject(”Scripting.Dictionary”);
for(var i=0;i<15000;i ){
d.Item(i)=”sdfdsffdsaf”;}
1.5w次插值,172ms
当然自定义对象var d=new Object(); d[i]=..更快,1.5w次只要80-90ms,不过功能弱多了,所以还是用字典.
下面看正式测试
for(var i=0;i<15000;i ){
Application.Lock();
Application.StaticObjects(”dict”).Item(i)=”sdfdsffdsaf”;
Application.Unlock();}
时间长达6953ms,初步判断StaticObjects集合de访问速度是不能满足Cachede要求了,这个速度和ADO OLEDB读sql server 2000de时间相差无几.
不过还不打算马上放弃,因为StaticObjectsde优势在于可以存放Object,而Dictionary也可以存放其它对象,这样可以做为缓存对象,而不仅仅是数据.
我在Application.StaticObjects(”dict”)里面再放入一个Object:
Application.StaticObjects(”dict”).Item(”o”)=new Object();
for(var i=0;i<15000;i ){
Application.Lock();
Application.StaticObjects(”dict”).Item(”o”)[i]=”sdfdsffdsaf”;
Application.Unlock();}
6656ms,快了点点.多一层Object并没有降低速度,那么速度de慢并非结构复杂,而是StaticObjectsde访问占用.
把dictde引用预存
var t=Application.StaticObjects(”dict”);
for(var i=0;i<15000;i ){
Application.Lock();
t.Item(”o”)[i]=”sdfdsffdsaf”;
Application.Unlock();}
3094ms,成功de减少一半多点de时间,js中屡试不爽de预存策略,要是把t.Item(”o”)也预存呢?
var t=Application.StaticObjects(”dict”).Item(”o”);
for(var i=0;i<15000;i ){
Application.Lock();
t[i]=”sdfdsffdsaf”;
Application.Unlock();}
125ms,终于成功了,只有Application.Contentsde一半.看来时间主要花费在取得’引用’,而不是StaticObjects内存区被保护慢.StaticObjects相对Contents安全措施更好,因为里面要存对象.
靠Dictionary强大de功能,适当de封装一下,用put(),get(),contains()等等流行方法访问,就是一个强大deCache了.
////备注
我封装了一个.sct组件;asp javascript写de,有空发上来,今天到此.
测试了取得Contens和StaticObjects引用de速度,在20次时都是0ms,100次大约5倍速度,500-1500次是10倍速度差距.不过取得后存取不受影响.

在JScript中使用缓存技术的实际代码

星期一, 06月 2nd, 2008

在使用VBScript时,我可以用Application缓存数组来实现缓存,例:
程序相关代码:
[复制此相关代码]CODE:
Dim rs,arr
rs.Open conn,sql,1,1
arr=rs.GetRows()
Application.Lock()
Application(”cache”)=arr
Applicatoin.UnLock()

在VBScript里,数组是可以存到Application对象里de,但是如果ASPde语言选择为JScriptde话,那么就有些不妙了,我在使用Application储存一个数组时,会出现以下错误:
引用内容:
Application object, ASP 0197 (0×80004005)
Disallowed object use
Cannot add object with apartment model behavior to the application intrinsic object.
在微软de知识库可以找到具体原因如下:
引用内容:
JScript arrays are considered to be “Apartment” COM components. Only Component Object Model (COM) components that aggregate the Free Threaded Marshaler (FTM) can be assigned to Application scope within an Internet Information Server (IIS) 5.0 ASP page. Because an “Apartment” component cannot aggregate the FTM (it cannot allow a direct pointer to be passed to its clients, unlike a “Both with FTM” object), JScript arrays do not aggregate the FTM. Therefore, JScript arrays cannot be assigned to Application scope from an ASP page.
以上描述引用自:PRB: Error When You Store a JScript Array in Application Scope in IIS 5.0
因此,为了解决这个问题,在Google里找了一大会,终于找到了一篇文章《Application对象deContents和StaticObjects做Cachede一些结论》,解决了这个问题,方法就是使用Application.StaticObject存放一个Scripting.Dictionary对象,然后再使用Scripting.Dictionary对象来存放需要缓存de数据.
据此,写了一个操作缓存de类,实现put、get、remove和clear方法,使用之前,需要在global.asa中添加一个object:
程序相关代码:
<object id=”xbsCache” runat=”server” scope=”Application” progid=”Scripting.Dictionary”></object>
类de实现如下:
[复制此相关代码]CODE:
<script language=”JScript” runat=”server”>
/**
Title: cache operate class
Description: operate system cache
@Copyright: Copyright (c) 2007
@Author: xujiwei
@Website: http://www.xujiwei.cn/
@Version: 1.0
@Time: 2007-06-29 12:03:45
**/
var xbsCache = {
get: function(key) {
return Application.StaticObjects(”xbsCache”).Item(”Cache.” key);
},
put: function(key, data) {
Application.Lock();
Application.StaticObjects(”xbsCache”).Item(”Cache.” key)=data;
Application.UnLock();
},
remove: function(key) {
Application.Lock();
Application.StaticObjects(”xbsCache”).Remove(”Cache.” key);
Application.UnLock();
},
clear: function() {
Application.Lock();
Application.StaticObjects(”xbsCache”).RemoveAll();
Application.UnLock();
}
}
</script>
如此,就完成了ASP中使用JScript时de缓存实现.

在ASP里面创建GUID

星期一, 06月 2nd, 2008

相关代码如下:
JScript
[复制此相关代码]CODE:
function GenerateGuid() {
var TypeLib = new ActiveXObject(”Scriptlet.TypeLib”);
return (TypeLib.Guid);
}

VBScript
[复制此相关代码]CODE:
Function GenerateGuid()
Dim TypeLib
Set TypeLib = Server.CreateObject(”Scriptlet.TypeLib”)
GenerateGuid = TypeLib.Guid
End Function

如果要在客户端使用de话,VBScriptde相关代码需要稍做修改,即把:
Set TypeLib = Server.CreateObject(”Scriptlet.TypeLib”)
修改为:
Set TypeLib = CreateObject(”Scriptlet.TypeLib”)
但是在客户端使用ActiveXde时候,IE默认de安全设置会提示是否允许使用ActiveX,所以并不推荐使用.

解决 JScript 中使用日期类型数据时出现类型错误的问题

星期一, 06月 2nd, 2008

例如以下相关代码:
程序相关代码:
[复制此相关代码]CODE:
<%@LANGUAGE=”JScript” CODEPAGE=”65001″%>
<script language=”JScript” runat=”server”>
Response.Cookies(”xujiwei”)(”name”) = “xujiwei”;
Response.Cookies(”xujiwei”)(”gender”) = “male”;
var expiredDate = new Date(2008, 11, 31);
Response.Cookies(”xujiwei”).Expires = expiredDate;
</script>

在浏览器中打开之后,就会出现以下错误:
引用内容:
Microsoft JScript 运行时错误 错误 ”800a000d”
类型不匹配
/temp/test.asp,行 6
这就意味着,我按照类似在VBScript里de使用日期类型数据de方法在JScript不再行得通,但是我总是需要在服务端中使用日期类型数据de,如果操作数据库是采用参数化Commandde方式de话,那么需要使用日期类型数据de地方会更多,总不能因为不能使用常规方法来添加一个日期参数而把它放在SQL语句里吧.
幸好,JScriptde设计者们考虑到了这一点.JScript在服务端使用时,往往是做为ASPde另一种脚本语言,而JScript则是微软在JavaScript上发展而来de微软自己de东西,考虑到这一点也是应该de.
在JScript中,解决这一问题de关键就是,Date类型de对象提供了一个函数getVarDate,它在JScript语言参考de说明如下:
引用内容:
当与 COM 对象、ActiveX® 对象或其他以 VT_DATE 格式接受和返回日期值de对象(例如 Visual Basic 和 VBScript)进行交互时,使用 getVarDate 方法.实际格式取决于地区设置,不随 JScript 变化.
好了,到现在问题de解决方法也已经浮出水面,就是使用getVarDate()函数将Date类型对象转换成可以与ASP中内置对象Response等可以交互de日期类型对象,那么将一开始de相关代码修改如下:
程序相关代码:
[复制此相关代码]CODE:
<%@LANGUAGE=”JScript” CODEPAGE=”65001″%>
<script language=”JScript” runat=”server”>
Response.Cookies(”xujiwei”)(”name”) = “xujiwei”;
Response.Cookies(”xujiwei”)(”gender”) = “male”;
var expiredDate = new Date(2008, 11, 31);
Response.Cookies(”xujiwei”).Expires = expiredDate.getVarDate();
</script>

再在浏览器打开这个测试页面de时候,就不再会有错误信息出现,说明客户端deCookies成功写入并设置了到期时间为2008年12月31日.
希望此文对您有所帮助.

分享一个好东东,动态Include文件 (Dynamic File Includes)

星期一, 06月 2nd, 2008

早在03年就在蓝色理想上看到过动态Includede文章,当时已经觉得很厉害,但实际应用了一下,不方便而且Includede效果不好.
后来又在一网站上看到了改进版de,但是也不太好用~~~
哎,当时我真是觉得有点想放弃ASP了,但是由于公司还是用ASP来开发,我也是没有办法…
今天,我一定要记住今天~~~在国外de一个网站上我竟然发现了这样一个好东东,太棒了~~~Great works!!!
以前试de一些动态Include相关代码,都无法Include一个类,甚至函数~~~又或者Include文件中deInclude无法被包含…
现在这个鬼佬(dselkirk)写de类可以为我做到这些了~~~
[复制此相关代码]CODE:
<%
public include, include_vars
set include = new cls_include
class cls_include
private sub class_initialize()
set include_vars = server.createobject(”scripting.dictionary”)
end sub
private sub class_deactivate()
arr_variables.removeall
set include_vars = nothing
set include = nothing
end sub
public default function include(byval str_path)
dim str_source
if str_path <> “” then
str_source = readfile(str_path)
if str_source <> “” then
processincludes str_source
convert2code str_source
formatcode str_source
if str_source <> “” then
if request.querystring(”debug”) = 1 then
response.write str_source
response.end
else
executeglobal str_source
include_vars.removeall
end if
end if
end if
end if
end function
private sub convert2code(str_source)
dim i, str_temp, arr_temp, int_len
if str_source <> “” then
if instr(str_source,”%” & “>”) > instr(str_source,”<” & “%”) then
str_temp = replace(str_source,”<” & “%”,”|%”)
str_temp = replace(str_temp,”%” & “>”,”|”)
if left(str_temp,1) = “|” then str_temp = right(str_temp,len(str_temp) - 1)
if right(str_temp,1) = “|” then str_temp = left(str_temp,len(str_temp) - 1)
arr_temp = split(str_temp,”|”)
int_len = ubound(arr_temp)
if (int_len 1) > 0 then
for i = 0 to int_len
str_temp = trim(arr_temp(i))
str_temp = replace(str_temp,vbcrlf & vbcrlf,vbcrlf)
if left(str_temp,2) = vbcrlf then str_temp = right(str_temp,len(str_temp) - 2)
if right(str_temp,2) = vbcrlf then str_temp = left(str_temp,len(str_temp) - 2)
if left(str_temp,1) = “%” then
str_temp = right(str_temp,len(str_temp) - 1)
if left(str_temp,1) = “=” then
str_temp = right(str_temp,len(str_temp) - 1)
str_temp = “response.write ” & str_temp
end if
else
if str_temp <> “” then
include_vars.add i, str_temp
str_temp = “response.write include_vars.item(” & i & “)”
end if
end if
str_temp = replace(str_temp,chr(34) & chr(34) & ” & “,”")
str_temp = replace(str_temp,” & ” & chr(34) & chr(34),”")
if right(str_temp,2) <> vbcrlf then str_temp = str_temp
arr_temp(i) = str_temp
next
str_source = join(arr_temp,vbcrlf)
end if
else
if str_source <> “” then
include_vars.add “var”, str_source
str_source = “response.write include_vars.item(”"var”")”
end if
end if
end if
end sub
private sub processincludes(str_source)
dim int_start, str_path, str_mid, str_temp
str_source = replace(str_source,”<!– #”,”<!–#”)
int_start = instr(str_source,”<!–#include”)
str_mid = lcase(getbetween(str_source,”<!–#include”,”–>”))
do until int_start = 0
str_mid = lcase(getbetween(str_source,”<!–”,”–>”))
int_start = instr(str_mid,”#include”)
if int_start > 0 then
str_temp = lcase(getbetween(str_mid,chr(34),chr(34)))
str_temp = trim(str_temp)
str_path = readfile(str_temp)
str_source = replace(str_source,”<!–” & str_mid & “–>”,str_path & vbcrlf)
end if
int_start = instr(str_source,”#include”)
loop
end sub
private sub formatcode(str_code)
dim i, arr_temp, int_len
str_code = replace(str_code,vbcrlf & vbcrlf,vbcrlf)
if left(str_code,2) = vbcrlf then str_code = right(str_code,len(str_code) - 2)
str_code = trim(str_code)
if instr(str_code,vbcrlf) > 0 then
arr_temp = split(str_code,vbcrlf)
for i = 0 to ubound(arr_temp)
arr_temp(i) = ltrim(arr_temp(i))
if arr_temp(i) <> “” then arr_temp(i) = arr_temp(i) & vbcrlf
next
str_code = join(arr_temp,”")
arr_temp = vbnull
end if
end sub
private function readfile(str_path)
dim objfso, objfile
if str_path <> “” then
if instr(str_path,”:”) = 0 then str_path = server.mappath(str_path)
set objfso = server.createobject(”scripting.filesystemobject”)
if objfso.fileexists(str_path) then
set objfile = objfso.opentextfile(str_path, 1, false)
if err.number = 0 then
readfile = objfile.readall
objfile.close
end if
set objfile = nothing
end if
set objfso = nothing
end if
end function
private function getbetween(strdata, strstart, strend)
dim lngstart, lngend
lngstart = instr(strdata, strstart) len(strstart)
if (lngstart <> 0) then
lngend = instr(lngstart, strdata, strend)
if (lngend <> 0) then
getbetween = mid(strdata, lngstart, lngend - lngstart)
end if
end if
end function
end class
%>

ASP中使用FileSystemObject时提高性能的方法

星期一, 06月 2nd, 2008

按个测试了一下可能会是哪些属性引起de性能问题,在去掉Type也就是类型属性显示de时候,性能有了很大提高,之后de测试也证明了是Type属性de使用导致了性能问题.
仔细想了一下,Type引起性能低de原因应该是,引用Type属性所得到de是文件de具体类型信息,也就是我在资源浏览器里看到de那样,比如TXT文件de类型就是显示为“文本文档”,但是这个类型信息却是存储在系统中,通过文件扩展名进行关联de.在FSO中使用Type属性de时候,对于每个File对象,FSO都需要根据扩展名去系统中检索这个扩展名对应de类型名称,这样,就极大de降低了性能.
因此,在使用FileSystemObject时,如果可以不使用File或者Folder对象deType属性,就尽量不使用.
希望此文对您有所帮助.

ASP注册登陆实例代码

星期一, 06月 2nd, 2008


数据库位置:data/data.mdb
数据库表:user
id name pwd wenti daan
conn.asp
<%
db=”data/data.mdb” ‘数据库存放目录
on error resume next
set conn=server.createobject(”adodb.connection”)
conn.open “driver={microsoft access driver (*.mdb)};dbq=”&server.mappath(db)
if err then
err.clear
set conn = Nothing
response.write “数据库连接出错,请检查conn.asp中de连接字符串.”
response.end
end if
function CloseDB
Conn.Close
set Conn=Nothing
End Function
%>
<%
dim badword
badword=”‘|and|select|update|chr|delete| from|;|insert|mid|master.|set|chr(37)|=”
if request.QueryString<>”" then
chk=split(badword,”|”)
for each query_name in request.querystring
for i=0 to ubound(chk)
if instr(lcase(request.querystring(query_name)),chk(i))<>0 then
response.write “<script language=javascript>alert(’传参错误!参数 “&query_name&” de值中包含非法字符串!\n\n’);location=’”&request.ServerVariables (”HTTP_REFERER”)&”‘</Script>”
response.end
end if
next
next
end if
%>
reg.asp
<!–#i nclude file=”conn.asp”–>
<%
if request(”action”)=”reg” then
set rs=server.CreateObject(”adodb.recordset”)
rs.open “select * from user where name=’”&trim(request(”name”))&”‘”,conn,1,1
if rs.recordcount>0 then
response.write “<Script language=’JavaScript’>window.alert(’您输入de用户名已存在,请返回重新输入!’);history.back(-1);</Script>”
response.End()
end if
sql=”select * from user”
set rs=server.createobject(”adodb.recordset”)
rs.open sql,conn,1,3
rs.addnew
rs(”name”)=trim(request.Form(”name”))
rs(”pwd”)=trim(request.Form(”pwd”))
rs(”wenti”)=trim(request.Form(”wenti”))
rs(”daan”)=trim(request.Form(”daan”))
rs.update
rs.close
set rs=nothing
response.write “<script language=javascript> alert(’注册成功,点击确定立即登录!’);location.replace(’login.asp’);</script>”
response.end
end if
%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td>用户注册
<form name=”form1″ method=”post” action=”?action=reg” onsubmit=”return chkform(this)”>
<table width=”347″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td width=”142″>用户名</td>
<td width=”179″><input name=”name” type=”text” id=”name”></td>
</tr>
<tr>
<td>密码</td>
<td><input name=”pwd” type=”password” id=”pwd”></td>
</tr>
<tr>
<td>密码提示问题</td>
<td><input name=”wenti” type=”text” id=”wenti”></td>
</tr>
<tr>
<td>密码提示答案</td>
<td><input name=”daan” type=”text” id=”daan”></td>
</tr>
<tr>
<td colspan=”2″><input type=”submit” name=”Submit” value=”注册”>
<input type=”reset” name=”Submit” value=”重置”> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

top.asp
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td><a href=”/”";index.asp”>首页</a>
<%
if Session(”name”)=”" then
%>
<a href=”/”";reg.asp”>注册</a> <a href=”/”";login.asp”>登陆</a>
<a href=”/”";pwd.asp”>忘记密码?</a> <%
else
%>
欢迎您<%=Session(”name”)%>, <a href=”/”";loginout.asp”>注销登陆</a>
<%
end if
%>
<a href=”/”";jiami.asp”>加密页</a></td>
</tr>
</table>
<br>
login.asp
<!–#i nclude file=”conn.asp”–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td>
用户登陆
<%
if Session(”name”)=”" then
%>
<form name=”form1″ method=”post” action=”loginok.asp?action=login” onsubmit=”return chkform(this)”>
<table border=”1″ cellspacing=”0″ cellpadding=”5″>
<tr>
<td width=”116″>用户名</td>
<td width=”116″><input name=”name” type=”text” id=”name”></td>
</tr>
<tr>
<td>密码</td>
<td><input name=”pwd” type=”password” id=”pwd”></td>
</tr>
<tr>
<td colspan=”2″><input type=”submit” name=”Submit” value=”登陆”>
<input type=”reset” name=”Submit” value=”重置”></td>
</tr>
</table>
</form>
<%
else
%>
<table border=”1″ cellspacing=”0″ cellpadding=”5″>
<tr>
<td width=”303″><%=Session(”name”)%>,您已经成功登陆</td>
</tr>
</table>
<%
end if
%>
</td>
</tr>
</table>
</body>
</html>

loginok.asp
<!–#i nclude file=”conn.asp”–>
<%
Session.TimeOut=30
if request(”action”)=”login” then
name=trim(request.form(”name”))
pwd=trim(request.form(”pwd”))
if name=”" or pwd=”" then
Response.Redirect (”login.asp”)
end if
set rs=server.createobject(”adodb.recordset”)
sql=”select * from user where name=’”&name&”‘and pwd=’”&pwd&”‘”
rs.open sql,conn,1,1
if not rs.eof then
session(”name”)=name
response.redirect”edit.asp”
else
response.redirect”Error.asp”
response.end
end if
end if
%>
loginout.asp
<%
session(”name”)=”"
response.write “<script language=javascript> alert(’退出登陆成功!’);location.href(’index.asp’);</script>”
response.end
%>
pwd.asp
<!–#i nclude file=”conn.asp”–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td><p>找回密码</p>
<form name=”form1″ method=”post” action=”pwd2.asp?action=pwd”>
<table width=”398″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td width=”130″>请输入用户名</td>
<td width=”168″><input name=”name” type=”text” id=”name”></td>
<td width=”62″><input type=”submit” name=”Submit” value=”查询”></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>

pwd2.asp
<!–#i nclude file=”conn.asp”–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td>
找回密码
<%
name=trim(request.form(”name”))
set rs=server.createobject(”adodb.recordset”)
sql=”select * from user where name=’”&name&”‘”
rs.open sql,conn,1,1
if not rs.eof then
%>
<form name=”form1″ method=”post” action=”pwd3.asp”>
<table width=”398″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td><%=rs(”name”)%></td>
<td> </td>
<td><input name=”name” type=”hidden” id=”name” value=”<%=rs(”name”)%>”></td>
</tr>
<tr>
<td width=”130″>密码提示问题</td>
<td width=”168″><%=rs(”wenti”)%>
</td>
<td width=”62″> </td>
</tr>
<tr>
<td>密码提示答案</td>
<td><input name=”daan” type=”text” id=”daan”></td>
<td><input type=”submit” name=”Submit” value=”查询”></td>
</tr>
</table>
</form>
<% else
%>
<table width=”413″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
< td>您输入de用户名不存在,请<a href=”/”";javascript:history.back()”>返回</a>重新输入,或者<a href=”/”";reg.asp”>注册</a></td>
</tr>
</table>
<%end if
%>
</td>
</tr>
</table>
</body>
</html>

pwd3.asp
<!–#i nclude file=”conn.asp”–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td>
找回密码
<%
name=trim(request.form(”name”))
daan=trim(request.form(”daan”))
set rs=server.createobject(”adodb.recordset”)
sql=”select * from user where name=’”&name&”‘ and daan=’”&daan&”‘”
rs.open sql,conn,1,1
if not rs.eof then
%>

<table width=”398″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td width=”130″><%=rs(”name”)%>,您de密码</td>
<td><%=rs(”pwd”)%>
</td>
</tr>
</table>
<% else
%>
<table width=”413″ border=”1″ cellpadding=”5″ cellspacing=”0″>
<tr>
<td>您输入de密码提示答案不正确,请<a href=”/”";javascript:history.back()”>返回</a>重新输入</td>
</tr>
</table>
<%end if
%>
</td>
</tr>
</table>
</body>
</html>

error.asp
<!–#i nclude file=”conn.asp”–>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td>登陆失败,请检查用户名和密码是否正确 <a href=”/”";login.asp”>返回</a></td>
</tr>
</table>
</body>
</html>

edit.asp
<!–#i nclude file=”conn.asp”–>
<%
if request(”action”)=”edit” then
name=session(”name”)
set rs=server.createobject(”adodb.recordset”)
sql=”select * from user where name=’”&name&”‘”
rs.open sql,conn,3,2
rs(”pwd”)=trim(request.Form(”pwd”))
rs(”daan”)=trim(request.Form(”daan”))
rs.update
rs.close
set rs=nothing
response.write “<script language=javascript>alert(’编辑成功!’);location.href(’edit.asp’);</script>”
end if
%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>无标题文档</title>
</head>
<body><!–#i nclude file=”top.asp”–>
<table width=”90%” border=”1″ align=”center” cellpadding=”10″ cellspacing=”0″>
<tr>
<td><p>修改资料</p>
<p>
<%
if Session(”name”)=”" then
%>
对不起您还没有登陆,请<a href=”/”";login.asp”>登陆</a>或者<a href=”/”";reg.asp”>注册</a>
<%
else
%>
<%
name=session(”name”)
set rs=server.createobject(”adodb.recordset”)
sql=”select * from user where name=’”&name&”‘”
rs.open sql,conn,1,1
%>
</p>
<form action=”?action=edit” method=”post” name=”form” id=”form”>
<table border=”1″ cellpadding=”5″>
<tr>
<td>用户名</td>
<td><%=rs(”name”)%></td>
</tr>
<tr>
<td>密码</td>
<td><input name=”pwd” type=”text” id=”pwd” value=”<%=rs(”pwd”)%>”></td>
</tr>
<tr>
<td>密码提示问题</td>
<td><%=rs(”wenti”)%></td>
</tr>
<tr>
<td>密码提示答案</td>
<td><input name=”daan” type=”text” id=”daan” value=”<%=rs(”daan”)%>”></td>
</tr>
<tr>
<td> </td>
<td><input type=”submit” name=”Submit” value=”修改”>
<input type=”reset” name=”Submit” value=”重置”></td>
</tr>
</table>
</form>
<p> <%
end if
%>
</p></td>
</tr>
</table>
</body>
</html>

asp采集抓取网上房产信息的代码

星期一, 06月 2nd, 2008

[复制此相关代码]CODE:
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<!– #include file=”conn.asp” –>
<!– #include file=”inc/function.asp” –>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<meta http-equiv=”refresh” content=”300;URL=steal_house.asp”>
</head>
<body>
<%
on error resume next

Server.ScriptTimeout = 999999
‘========================================================
‘字符编码函数
‘====================================================
Function BytesToBstr(body,code)
dim objstream
set objstream = Server.CreateObject(”adodb.stream”)
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset =code
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
‘取行字符串在另一字符串中de出现位置
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
‘替换字符串函数
function ReplaceStr(ori,str1,str2)
ReplaceStr=replace(ori,str1,str2)
end function
‘====================================================
function ReadXml(url,code,start,ends)
set oSend=createobject(”Microsoft.XMLHTTP”)
SourceCode = oSend.open (”GET”,url,false)
oSend.send()
ReadXml=BytesToBstr(oSend.responseBody,code )
start=Instr(ReadXml,start)
ReadXml=mid(ReadXml,start)
ends=Instr(ReadXml,ends)
ReadXml=left(ReadXml,ends-1)
end function
function SubStr(body,start,ends)
start=Instr(body,start)
SubStr=mid(body,start len(start) 1)
ends=Instr(SubStr,ends)
SubStr=left(SubStr,ends-1)
end function
dim getcont,NewsContent
dim url,title
url=”http://www.***.com”‘新闻网址
getcont=ReadXml(url,”gb2312″,”<table class=k2 border=”"0″”",”</table>”)
getcont=RegexHtml(getcont)
dim KeyId,NewsClass,City,Position,HouseType,Level,Area,Price,Demostra
dim ContactMan,Contact
for i=2 to ubound(getcont)
response.Write(getcont(i)&”__<br>”)
tempLink=mid(getcont(i),instr(getcont(i),”href=”"”) 6,instr(getcont(i),”"”
onClick”)-10)
tempLink=replace(tempLink,”../”,”")
response.Write(i&”:”&tempLink&”<br>”)
NewsContent=ReadXml(tempLink,”gb2312″,”<td valign=”"bottom”"
width=”"400″”>”,”<hr width=”"760″”
noshade size=”"1″” color=”"#808080″”>
“)
NewsContent=RemoveHtml(NewsContent)
NewsContent=replace(NewsContent,VbCrLf,”")
NewsContent=replace(NewsContent,vbNewLine,”")
NewsContent=replace(NewsContent,” “,”")
NewsContent=replace(NewsContent,” “,”")
NewsContent=replace(NewsContent,” “,”")
NewsContent=replace(NewsContent,”\n”,”")
NewsContent=replace(NewsContent,chr(10),”")
NewsContent=replace(NewsContent,chr(13),”")
‘===============get Content=======================
response.Write(NewsContent)
KeyId=SubStr(NewsContent,”列号:”,”信息类别:”)
NewsClass=SubStr(NewsContent,”类别:”,”所在城市:”)
City=SubStr(NewsContent,”城市:”,”房屋具体位置:”)
Position=SubStr(NewsContent,”位置:”,”房屋类型:”)
HouseType=SubStr(NewsContent,”类型:”,”楼层:”)
Level=SubStr(NewsContent,”楼层:”,”使用面积:”)
Area=SubStr(NewsContent,”面积:”,”房价:”)
Price=SubStr(NewsContent,”房价:”,”其他说明:”)
Demostra=SubStr(NewsContent,”说明:”,”联系人:”)
ContactMan=SubStr(NewsContent,”联系人:”,”联系方式:”)
Contact=SubStr(NewsContent,”联系方式:”,”信息来源:”)
response.Write(”总序列号:”&KeyId&”<br>”)
response.Write(”信息类别:”&NewsClass&”<br>”)
response.Write(”所在城市:”&City&”<br>”)
response.Write(”房屋具体位置:”&Position&”<br>”)
response.Write(”房屋类型:”&HouseType&”<br>”)
response.Write(”楼层:”&Level&”<br>”)
response.Write(”使用面积:”&Area&”<br>”)
response.Write(”房价:”&Price&”<br>”)
response.Write(”其他说明:”&Demostra&”<br>”)
response.Write(”联系人:”&ContactMan&”<br>”)
response.Write(”联系方式:”&Contact&”<br>”)
‘title=RemoveHTML(aa(i))
‘response.Write(”title:”&title)
for n=0 to application.Contents.count
if(application.Contents(n)=KeyId) then
ifexit=true
end if
next
if not ifexit then
application(time&i)=KeyId
‘添加到数据库
‘====================================================
set rs=server.CreateObject(”adodb.recordset”)
rs.open “select top 1 * from news order by id desc”,conn,3,3
rs.addnew
rs(”NewsClass”)=NewsClass
rs(”City”)=City
rs(”Position”)=Position
rs(”HouseType”)=HouseType
rs(”Level”)=Level
rs(”Area”)=Area
rs(”Price”)=Price
rs(”Demostra”)=Demostra
rs(”ContactMan”)=ContactMan
rs(”Contact”)=Contact
rs.update
rs.close
set rs=nothing
end if
‘==================================================
next
function RemoveTag(body)
Set regEx = New RegExp
regEx.Pattern = “<[a].*?<\/[a]>”
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(body)
dim i,arr(15),ifexit
i=0
j=0
For Each Match in Matches
TempStr = Match.Value
TempStr=replace(TempStr,”<td>”,”")
TempStr=replace(TempStr,”</td>”,”")
TempStr=replace(TempStr,”<tr>”,”")
TempStr=replace(TempStr,”</tr>”,”")
arr(i)=TempStr
i=i 1
if(i>=15) then
exit for
end if
Next
Set regEx=nothing
Set Matches =nothing
RemoveTag=arr
end function
function RegexHtml(body)
dim r_arr(47),r_temp
Set regEx2 = New RegExp
regEx2.Pattern =”<a.*?<\/a>”
regEx2.IgnoreCase = True
regEx2.Global = True
Set Matches2 = regEx2.Execute(body)
iii=0
For Each Match in Matches2
r_arr(iii)=Match.Value
iii=iii 1
Next
RegexHtml=r_arr
set regEx2=nothing
set Matches2=nothing
end function
‘======================================================
conn.close
set conn=nothing
%>
</body>
</html>

ASP计算str2在str1中出现的次数

星期一, 06月 2nd, 2008

function CountStr(str1,str2)
dim tmp,i,j
if str1=”" or isnull(str1) then
j=0
elseif str2=”" or isnull(str2) then
j=1
else
tmp=split(str1,str2)
j=0
for i=0 to ubound(tmp)
if tmp(i)<>”" then j=j 1
next
end if
countstr=j
end function