新浪首页免费邮件用户注册网站地图
上移动梦网
赢手机大奖

新浪首页 > 科技时代 > 网上学园 > 主页制作 > 正文
用ASP为你的站点加密

http://www.sina.com.cn 2001/08/13 10:43 赛迪网 汤宇时

  正在学习建设web站点的读者,可能正在为站点的安全性而担忧;也许你正在建设一个非公开性网站,只有系统用户才可以访问你的站点。如果你编制的是ASP网页,那么你可以通过本文轻松达到这一目的。

  首先,你需要制作登录页面,在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 customerswherescust—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″将自动导航到你的登录界面。

  在这样处理之后,恭喜你,你的web站点就有了安全登录的功能。即使别人知道了你的站点的地址,在不进行合法登录的情况下,也无法访问其他网页。并且,在你的网页超时后,需要用户重新登录,这样即便操作者临时离开,也不必担心非法者的恶意操作。(责任编辑Ray)



发表评论】【初学者园地】【科技聊天】【关闭窗口

新 闻 查 询

 相关链接
【学园专题】主页制作步步高
用Delphi开发ASP分页组件 (2001/07/31 10:57)
用ASP让用户访问指定页面 (2001/07/13 11:12)
利用ASP在浏览器上打印输出 (2001/06/29 14:09)
ASP实现简单的网页保护功能 (2001/06/29 12:46)


科技时代意见反馈留言板 电话:010-82612286   欢迎批评指正

网站简介 | 用户注册 | 广告服务 | 招聘信息 | 中文阅读 | Richwin | 联系方式 | 帮助信息 | 网站律师

Copyright © 1996 - 2001 SINA.com, Stone Rich Sight. All Rights Reserved

版权所有 四通利方 新浪网