如何制作一个安全的页面?
程序员文章站
2022-04-15 09:22:08
manage.asp' 登录页面.<%@ language=vbscript %>
<% response.buffer = true %>
<html>
<body>
<% session("allow") = true %>
<%
username = request.form("username")
password = request.form("password")
' 抓取表单内容.
set myconn=server.createobject("adodb.connection")
myconn.open "连接字符串"
sql = "select * from tbllogin"
set rs = myconn.execute(sql)
if username = rs("username") and password = rs("password") then
' 如果匹配则显示要保护的页面.
%>
----------------------------------------------------------------------------------------------------------------
' 此处放置要保护的页面的内容.
----------------------------------------------------------------------------------------------------------------
<%
else
response.redirect "http://www.intels.net/login.asp"
rs.close
myconn.close
set rs = nothing
set myconn = nothing
end if
%>
' 如果不匹配则返回登录页,让用户重新登录.
</body></html>
好了,让我们来做最后的应用工作吧,把下面的代码加入需要保护的页面的最前面:
<%@ language=vbscript %>
<% response.buffer = true %>
<% if session("allow") = false then response.redirect "manage.asp" %>
manage.asp
' 登录页面.
<%@ language=vbscript %>
<html>
<body>
<form name="login" method="post" action="login.asp">
<input type="text" name="username" size="20">用户名<br>
<input type="password" name="password" size="20">口令<br>
<input type="submit" name="btnlogin" value="登录">
</form>
</body></html>
login.asp
' 验证在表单中输入的用户名和口令.
<% response.buffer = true %>
<html>
<body>
<% session("allow") = true %>
<%
username = request.form("username")
password = request.form("password")
' 抓取表单内容.
set myconn=server.createobject("adodb.connection")
myconn.open "连接字符串"
sql = "select * from tbllogin"
set rs = myconn.execute(sql)
if username = rs("username") and password = rs("password") then
' 如果匹配则显示要保护的页面.
%>
----------------------------------------------------------------------------------------------------------------
' 此处放置要保护的页面的内容.
----------------------------------------------------------------------------------------------------------------
<%
else
response.redirect "http://www.intels.net/login.asp"
rs.close
myconn.close
set rs = nothing
set myconn = nothing
end if
%>
' 如果不匹配则返回登录页,让用户重新登录.
</body></html>
好了,让我们来做最后的应用工作吧,把下面的代码加入需要保护的页面的最前面:
<%@ language=vbscript %>
<% response.buffer = true %>
<% if session("allow") = false then response.redirect "manage.asp" %>
[1]
上一篇: 怎样避免直接在地址栏敲入URL即可绕过登录页的错误?
下一篇: 如何实现强制登录?