许可用户站点登录

来源:互联网 发布:淘宝可以买到的黑科技 编辑:程序博客网 时间:2024/04/29 23:35

建设一个非公开性网站,只有用户才可以访问你的站点。

首先,你需要制作登录页面,在html中加入form,并设为自发送页
<form name="login" action="default.ASP" method="post" target="_top">
action后接本页url,这样即使用户登录错误,在本页即获提示,而无须再返回前一页登录。在表单中加入
<input name="uid" size="10"maxlength="10" style="height: 21px; width: 101px">
<input name="pwd" type="password" size="10" maxlength="10"> 
完成html后,在页首填加程序代码如下:
<% ' send customer direct to main page if already logged in
if not isempty(session("cust_id")) and len(session("cust_id"))>0 then response.redirect("navigation/dashbrd.ASP")
 ' 在此添入你真正的主页url
end if
' set flags
blogin = false
berror = false
' check blank entries
if isempty(request("uid")) or len(request("uid")) = 0 or isempty(request("pwd")) or len(request("pwd")) = 0 then
 ' need to log in
 blogin = true
else
 ' check user credentials against db
 ... ' 检验你的数据库保存密码表中是否有该用户

 ' 此处放入连接数据库代码

 ' 其sql如下 "select * from customer where cust_id='  "& request("uid")& " '  and ' cust_pwd='  "& request("pwd")& " '  "

 ' 其中request("uid")和request("pwd") 为本页html中表单中的用户名和密码的text

 gbfound = false
 if not rscust.bof and not rscust.eof then
  gbfound = true
 end if
 if gbfound then
  ' record useful customer info in session variables
  session("cust_id") = rscust.fields("cust_id")
  '  此项为数据库中用户名
  session("cust_pwd") = rscust.fields("cust_pwd") ' 此项为数据库中用户密码
  session("power") = rscust.fields("power") ' 此项为数据库中用户权限[可选]
  ' update last login time [可选]
  ' rscust.activeconnection.execute ("update customer set cust_login = '  "& now &" '  where cust_id = "& session("cust_id") & " ")
  response.redirect("navigation/dashbrd.ASP") ' 真正主页url
 else
  ' uid and password not found
  berror = true blogin = true
 end if
 rscust.close
 ' close recordset
 mycn_login.close
 set mycn_login=nothing
 ' get all policy numbers held by customer
end if
%>

最后,你要做的就是在你的每一个页面的开头,加入以下代码:
<% if isempty(session("cust_id")) or len(trim(session("cust_id")) = 0 then %>
<script language="javascript" runat=client>
<!--
top.location.href = "../default.asp"
//-->
<script>
<%
response.end
end if
%>

其中,session("cust_id") 为注册的用户名。
top.location.href = "../default.asp" 将自动导航到你的登录界面。

原创粉丝点击