|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
上一节:修改记录 学习目的:基本的SESSION组件,总结response,request组件。 首先,有会员系统的任何程序都会用到检测是不是用户已经登陆这个步骤。这就用到了SESSION组件,下面我们 看一个代码来说明。 <% session("login")="yes" %> 这句话的意思就是在session里面定义一个login字符串变量,值为"yes",直接可以赋值,不需要声明。是不是很简朴? 假如我们做治理员登陆系统的话,首先是一段检测是不是治理员: if 是 then session("isadmin")=yes" else session("isadmin")="no" end if 在每一个需要治理员才能看的页面最前面加上: <% if not session("isaadmin")="yes" then response.redirect "login.htm" %> 这样一般用户就无法打开这个页面。解释一下response.redirect,它是转向的意思,后面的"login.htm"就是转向的文件。这样没有登陆的治理员是无法看到后面的内容的。 response组件基本就是用到response.write(),response.redirect() 分别是写字符串和转向的作用。 request基本就是request.form(),request.querystring() 分别是接受post,get方式传来的信息。 最后我们一起来制作一个简朴的后台登陆治理界面,首先在myweb目录下建立一个admin文件夹,然后我们建立一个数据库名字为 admin.mdb,然后我们再建立一个表,表中设置两个字段name,password,类型都是文本型的!最后退出时设置主键,保存为表名 check。然后可以输入一条记录用户名:admin,密码:admin。详细建立数据库的方式请看《菜鸟十天学会ASP教程之第三天:数据库的建立》 下面我们开始编写ASP程序,首先建立一个index.asp(治理主界面)程序,代码如下: <%@language=vbscript%> <%if not session("checked")="yes" then response.Redirect "login.asp" else %> <html> <head> <title>治理界面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <frameset cols="167,*" frameborder="YES" border="1" framespacing="1" rows="*" bordercolor="#666666"> <frame name="leftFrame" scrolling="auto" noresize src="left.asp"> <frame name="mainFrame" src="right.asp"> </frameset> <noframes> <body bgcolor="#FFFFFF" text="#000000"> </body> </noframes> </html> <%end if%> 在上面的代码中,大家可以看到用到login.asp,left.asp,right.asp程序 login.asp://登陆系统程序 <html> <head> <title>治理员入口</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> <!-- .topic { font-family: "宋体"; font-size: 11pt; font-weight: bold; color: #FFFFFF} .font { font-family: "宋体"; font-size: 10pt; font-weight: normal; color: #000000} .table { border-color: #666666 black; border-style: solid; border-top-width: 1pt; border-right-width: 0px; border-bottom-width: 1pt; border-left-width: 0px} .text { border: 1pt #999999 solid; height: 15pt} --> </style> </head> <body text="#000000" topmargin="0" bgcolor="#FFFFFF"> <table width="100%" border="0" cellpadding="0" cellspacing="0" align="center" height="100%"> <tr> <td height="129" valign="top" colspan="3"> </td> </tr> <tr> <td width="230" height="170" valign="top"> </td> <td valign="top" width="277"> <table width="100%" border="0" cellspacing="1" cellpadding="0" height="100%" bgcolor="#000000" align="center"> <tr> <td align="center" valign="middle" height="167"> <form name="form1" method="post" action="check.asp"> <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%"> <tr bgcolor="#62892C"> <td height="31" class="topic" colspan="2"> <div align="center">治理员入口<br> </div> </td> </tr> <tr> <td bgcolor="#87bc3c" colspan="2" class="table"> <div align="center"> <span class="font"> 治理员:</span> <input type="text" name="name" class="text" size="20" onMouseOver="this.focus()"> <br> <span class="font">密 码:</span> <input type="password" name="password" class="text" size="20" onMouseOver="this.focus()"><%if session("check")="wrong" then response.Write "<br><span class=\\\'font\\\'><font color=red>验证错误!</font></span>" end if%> </div> </td> </tr> <tr> <td bgcolor="#87bc3c" width="52%"> <div align="center" class="font"> <input type="reset" name="Submit2" value="重置" class="text"> </div> </td> <td bgcolor="#87bc3c" width="48%"> <div align="center" class="font"> <input type="submit" name="Submit22" value="提交" class="text"> </div> </td> </tr> </table> </form> </td> </tr> </table> </td> <td width="241" valign="top"> </td> </tr> <tr> <td height="123" valign="top" colspan="3"> </td> </tr> </table> </body> </html> 在上面的程序中用到一个检查用户和密码是否准确的程序check.asp://核对输入的用户和密码是否准确 <% dim name,password name=request.form("name") password=request.form("password") dim exec,conn,rs exec="select *from check where(name=\\\'"&name&"\\\' and password=\\\'"&password&"\\\')" set conn=server.createobject("adodb.connection") conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("admin.mdb") set rs=server.createobject("adodb.recordset") rs.open exec,conn if not rs.eof then rs.Close conn.Close session("checked")="yes" session("check")="right" response.Redirect "index.asp" else session("checked")="no" session("check")="wrong" response.Redirect "login.asp" end if %> left.asp://治理导航 <%@language=vbscript%> <%if not session("checked")="yes" then response.Redirect "login.asp" else %> <html> <head> <title>治理界面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body text="#000000" topmargin="0" bgcolor="#ffffff" leftmargin="10"> <div align="center"><a href="index.asp" target="_parent"><br> <br> 治理界面首页</a> <a href="exit.asp" target="_parent">退出</a><br> <br> </div> </body> </html> <%end if%> exit.asp://退出系统 <%@language=vbscript%> <% session("check")="" session("checked")="" response.redirect "login.asp" %> right.asp://详细治理的内容 <%@language=vbscript%> <%if not session("checked")="yes" then response.Redirect "login.asp" else %> <html> <title>治理界面</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body bgcolor="#ffffff" text="#000000" topmargin="20" class="title"> 这里是网页教学网的治理系统示例!请大家多研究使用! </body> </html> <%end if%> 返回类别: 教程 上一教程: 如何使用ASP建立虚拟的FTP服务器 下一教程: 一个美丽的点击计数器 您可以阅读与"菜鸟十天学会ASP教程之第九天:SESSION组件"相关的教程: · 菜鸟十天学会ASP教程之第十天:分页技术 · 菜鸟十天学会ASP教程之第二天:表单传送变量 · 菜鸟十天学会ASP教程之第六天:查询记录 · 菜鸟十天学会ASP教程之第三天:数据库的建立 · 菜鸟十天学会ASP教程之第四天:数据库的连接和读取 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |