首页技术asp代码,ASP代码解释

asp代码,ASP代码解释

编程之家2023-11-01122次浏览

大家好,关于asp代码很多朋友都还不太明白,今天小编就来为大家分享关于ASP代码解释的知识,希望对各位有所帮助!

asp代码,ASP代码解释

ASP代码解释

application.lock'锁定application

dim i

for i=1 to 40'一个循环

application("manage"& i)=""’设置这个application为空

application("water"& i)=""’设置这个application为空

next

asp代码,ASP代码解释

application.unlock’解开锁定

这个是一些ASP网站常用的缓存实现技术,把一些网站配置等常用的数据保存到application中,然后调用的时候就可以直接调用了

,application的lock机制是为了保证application数据的一致性,当application被锁定后,其他页面是不能更新的,必须等到解锁之后才能更新application中的数据

asp注册登陆代码

1,(index.asp用户登陆页面)

<!--#include file="conn.asp"-->

<!-- blog.soowooo.cn悠悠长假期-->

asp代码,ASP代码解释

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>会员</title>

<style type="text/css">

<!--

body,td,th{

font-family:宋体;

font-size: 14px;

}

-->

</style>

</head>

<body>

<center>

<p>会员注册系统</p>

<form name="form1" method="post" action="login.asp">

<table width="34%" border="0">

<tr>

<td width="33%" height="30">用户名:</td>

<td width="67%" height="30"><input name="username" type="text" id="username" size="15"></td>

</tr>

<tr>

<td height="30">密码:</td>

<td height="30"><input name="password" type="password" id="password" size="15"></td>

</tr>

<tr>

<td colspan="2" align="center"><input type="submit" name="Submit" value="确定">

<input type="reset" name="Submit" value="重置"></td>

</tr>

<tr>

<td colspan="2"><a rel="external nofollow" href="reg.asp" target="_self">注册</a></td>

</tr>

</table>

</form>

</center>

</body>

</html>

2,(login.asp用户数据处理文件)

<!--#include file="conn.asp"-->

<%

'打开数据库判断用户是否存在,info为表名,username为字段名

set rsc=server.createobject("adodb.recordset")

sqlc="select* from info where username='"&request.Form("username")&"' and password='"&request.Form("password")&"'"

rsc.open sqlc,conn,1,1

session("username")=rsc("username")

session("password")=rsc("password")

session.Timeout=30

set rsc=nothing

response.Redirect("change.asp")

'如果用户不存在,session("username")为空

%>

3,(change.asp用户信息修改页面)

<!--#include file="conn.asp"-->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>修改</title>

<style type="text/css">

<!--

body,td,th{

font-size: 14px;

}

-->

</style></head>

<center>

<body>

<br>

<%

set rsc=server.createobject("adodb.recordset")

sqlc="select* from info where username='"&session("username")&"' and password='"&session("password")&"'"

rsc.open sqlc,conn,1,1

nr=rsc("password")

username=rsc("username")

password=rsc("password")

sex=rsc("sex")

qq=rsc("qq")

mail=rsc("mail")

add=rsc("add")

personalinfo=rsc("personalinfo")

vv=rsc("ntime")

set rsc=nothing

if nr="" then

response.Redirect("index.asp")

end if

if strcomp(nr,request.Form("password"))=0 then

response.Write("欢迎你!"&request.Form("username"))

response.Write("你是在"&vv&"注册的")

session("username")=request.Form("username")

end if

if session("username")="" then

response.Redirect("index.asp")

end if

%>

<form name="form1" method="post" action="change.asp?ac=ch">

<table width="39%" height="105" border="0">

<tr>

<td width="27%" height="30">用户名:</td>

<td width="73%" height="30"><input name="username" type="text" id="username" value="<%=username%>">

*</td>

</tr>

<tr>

<td height="30">密码:</td>

<td height="30"><input name="password" type="text" id="password" value="<%=password%>">

*</td>

</tr>

<tr>

<td height="30">性别:</td>

<td height="30"><input name="sex" type="text" id="sex" value="<%=sex%>"></td>

</tr>

<tr>

<td height="30">QQ:</td>

<td height="30"><input name="qq" type="text" id="qq" value="<%=qq%>"></td>

</tr>

<tr>

<td height="30">Mail:</td>

<td height="30"><input name="mail" type="text" id="mail" value="<%=mail%>"></td>

</tr>

<tr>

<td height="30">地址:</td>

<td height="30"><input name="add" type="text" id="add" value="<%=add%>"></td>

</tr>

<tr>

<td>介绍</td>

<td><textarea name="personalinfo" cols="30" rows="6" id="personalinfo"><%=personalinfo%></textarea></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="Submit" value="修改">

<a rel="external nofollow" href="change.asp?se=y" target="_self">退出系统</a></td>

<% if strcomp(request.QueryString("se"),"y")=0 then

session("username")=""

response.Redirect("index.asp")

end if

%>

</tr>

</table>

</form>

<%

if strcomp(request.QueryString("ac"),"ch")=0 then

set rs=server.createobject("adodb.recordset")

sql="select* from info where username='"&session("username")&"'"

rs.open sql,conn,1,3

rs("username")=request.Form("username")

rs("password")=request.Form("password")

rs("mail")=request.Form("mail")

rs("sex")=request.Form("sex")

rs("qq")=request.Form("qq")

rs("add")=request.Form("add")

rs("personalinfo")=request.Form("personalinfo")

rs.update

set rs=nothing

response.Write("修改完成!")

end if

%>

</body>

</center>

</html>

4,(reg.asp新用户注册页面)

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>用户注册</title>

<style type="text/css">

<!--

body,td,th{

font-family:宋体;

font-size: 14px;

}

-->

</style>

</head>

<body>

<center>

用户注册<br>

<%

=request.QueryString("msg")

%>

<form name="form1" method="post" action="addnewdata.asp?ac=adduser">

<table width="39%" height="105" border="0">

<tr>

<td width="27%" height="30">用户名:</td>

<td width="73%" height="30"><input name="username" type="text" id="username">

*</td>

</tr>

<tr>

<td height="30">密码:</td>

<td height="30"><input name="password" type="password" id="password">

*</td>

</tr>

<tr>

<td height="30">确定密码:</td>

<td height="30"><input name="password2" type="password" id="password2">

*</td>

</tr>

<tr>

<td height="30">性别:</td>

<td height="30"><input name="sex" type="text" id="sex"></td>

</tr>

<tr>

<td height="30">QQ:</td>

<td height="30"><input name="qq" type="text" id="qq"></td>

</tr>

<tr>

<td height="30">Mail:</td>

<td height="30"><input name="mail" type="text" id="mail"></td>

</tr>

<tr>

<td height="30">地址:</td>

<td height="30"><input name="add" type="text" id="add"></td>

</tr>

<tr>

<td>个人介绍</td>

<td><textarea name="personalinfo" cols="30" rows="6" id="personalinfo"></textarea></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="Submit" value="提交"></td>

</tr>

</table>

</form>

</center>

</body>

</html>

5,(addnewdata.asp新用户注册数据处理文件)

<!--#include file="conn.asp"-->

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>成功</title>

</head>

<body>

<%

ac=request.QueryString("ac")

msg="注册错误信息"

if request.Form("username")="" then

msg=msg&"<br>"&"用户名不能为空"

end if

if strcomp(cstr(request.Form("password")),cstr(request.Form("password2")))<>0 then

msg=msg&"<br>"&"两次密码输入不同"

end if

if len(request.Form("password"))<6 then

msg=msg&"<br>"&"密码太简单"

end if

if strcomp(msg,"注册错误信息")>0 then

response.Redirect("reg.asp?msg="&msg)

end if

if ac="adduser" then

set rsc=server.createobject("adodb.recordset")

sql="select* from info where username='"&request.Form("username")&"'"

rsc.open sql,conn,1,1

ck=rsc("username")

set rsc=nothing

if ck<>"" then

msg=msg&"<br>"&"用户名被人注册"

response.Redirect("reg.asp?msg="&msg)

end if

dsql="select* from info where id is null"

set rs=server.createobject("adodb.recordset")

rs.open dsql,conn,1,3

rs.addnew

rs("username")=request.Form("username")

rs("password")=request.Form("password")

rs("mail")=request.Form("mail")

rs("sex")=request.Form("sex")

rs("qq")=request.Form("qq")

rs("add")=request.Form("add")

rs("personalinfo")=request.Form("personalinfo")

rs("ntime")=now

rs.update

set rs=nothing

%>

<center>

<a rel="external nofollow" href="index.asp" target="_self">注册成功,点击登陆</a>

</center>

<%

end if

%>

</body>

</html>

6,(conn.asp数据库连接文件)

<%

'连接数据库开始

dim conn,rs,sql

on error resume next

dbpath=server.mappath("userinfo.mdb")

set conn=server.createobject("adodb.connection")

conn.open"PROVIDER=Microsoft.jet.OLEDB.4.0;data source="&dbpath

'创建记录对象

set rs=server.createobject("adodb.recordset")

%>

7,(userinfo.mdb ACCESS数据库)

在ACCESS中建一个表,然后在这个表中建立字段名称

表名:info

字段名称数据类型

id自动编号

username文本

password文本

sex文本

quest文本

qq文本

mail文本

personalinfo文本

ntime文本

asp代码中&_是什么意思

你说的没错,是vb/vbscript的人为换行符,表示的意思是下句仍是这一句代码.它不是ASP的,是语言的,所以如果采用ASP+JS时则不会出现这个符号的!

JS是C族的语言,它是在每句代码结果后要加分号(换行号)表示该句程序写完了,可以运行的,这种要求在C#等中明显,而JS是一个宽松的环境,所以有时可以不写,一般都是最后一句不用写换行号的,但C#等要求严格,必须要写的!

B族的要求也是严格的,但是它的规定恰恰相反,它是在代码在一行中写不完时加上&_来表示本行代码未写完,下行与本行是一句代码,当然你可以在一行写完时不用这个的!所以这里虽称换行符,但起的作用是“续行”的作用。如果不改格式的情况下,这个符号是不可以去掉的。如果不好理解,它有点像是去掉其后的第一个换行符的样子。所以后边如果打上一个空行时,如果空行后边什么也没有,它是会出错的!如:

conn.open"provider= microsoft.jet.oledb.4.0;data source=info.mdb;"&_

"jet oledb:database password=;"

conn.open"provider= microsoft.jet.oledb.4.0;data source=info.mdb;"&_

"jet oledb:database password=;"这个就会出错!

寻求ASP代码

登录状态,都是用session来记录的,

默认session是20分钟,可以通过修改session.timeout=1440这是24小时。。

当然如果你还需要时间更久的话,可以通过写入COOKIES来实现,然后能过JS来判断关闭状态,来清除COOKIES就可以了。

还有一个办法:

设置页面为每15分钟自动刷新一次:比如:

<head>

<metahttp-equiv="Refresh"content="900000;url=sessionKeeper.asp">

<!--每隔900秒刷新一下自己,为了和服务器通讯一下,保持session不会丢-->

</head>

</html>

还有一些办法:

<scriptlanguage=javascript>

functionkeepsession(){

document.all["Back"].src="/SessionKeeper.asp?RandStr="+Math.random();

//这里的RandStr=Math.random只是为了让每次back.src的值不同,防止同一地址刷新无效的情况

window.setTimeout("keepsession()",900000);//每隔900秒调用一下本身

}

keepsession();

</script>

在根目录建立一个空的SessionKeeper.asp文件就可以了,让JS通过指定时间来刷新一次,也可以保持SESSION的值。。。

建议还是不要做session保持,可以登录时加上个保持登录选项,如果选了就用cookies来实现就可以了。

OK,关于asp代码和ASP代码解释的内容到此结束了,希望对大家有所帮助。

火车头采集图片?火车头免费版如何采集图片北京搜索引擎优化?北京百度网站seo排名优化营销找谁做