ASP中怎么防止用户重复登陆:

zhuangbx220 2003-12-05 09:32:37
就是一个用户名,只能一个人登陆,不能在同一时刻登陆,只有等到前一用户退出后,这个用户名才能继续登陆

我刚学ASP,如果谁知道怎么做,麻烦你把源代码打出来.
...全文
218 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuangbx220 2003-12-09
  • 打赏
  • 举报
回复
session_onend 不执行
webdevelop 2003-12-09
  • 打赏
  • 举报
回复
建议用数据库,但一定要记得在关闭退出时返回数值,要不然就登陆不了了:)
zhuangbx220 2003-12-09
  • 打赏
  • 举报
回复
?????????????????????
zhuangbx220 2003-12-08
  • 打赏
  • 举报
回复
session_onend 不执行
yxisyx 2003-12-06
  • 打赏
  • 举报
回复
建议 用COOKIES 定时间 并判断ip来源前2位的方法
nattyfish 2003-12-05
  • 打赏
  • 举报
回复
<%@ Language=VBScript %>
<%
name = Request.Form("name")
passwd = Request.Form("passwd")
sql = "select name,passwd,type from usertype where name ='" & name & "'"
set conn = server.CreateObject("adodb.connection")
conn.Open Application("dsn")
set rs = server.CreateObject("adodb.recordset")
rs.Open sql,conn
if rs.EOF then
response.write "错误的用户名或密码!"
rs.Close
set rs = nothing
conn.Close
set conn = nothing
Response.End
end if

if not (rs("passwd") = passwd) then
response.write "错误的用户名或密码!"
rs.Close
set rs = nothing
conn.Close
set conn = nothing
Response.End
end if

session("username") = rs("name")
session("usertype") = rs("type")
rs.Close
set rs = nothing
sql = "update visit set visitnum = visitnum +1"
conn.Execute sql
conn.Close
set conn = nothing
Response.Redirect "frame.asp"
%>

在其他过页面加如
<%
if (isempty(session("username")) or len(session("username"))=0) then
Response.Redirect "error.asp"
end if
%>
yeno 2003-12-05
  • 打赏
  • 举报
回复
对session值进行判断,不知道ASP有没有这个功能,如果有的话,绝对可以解决问题
建立一临时表(不是临时建立的表)
再设置两个事件,当存入session("user")值时,也就是
当session("user")<>""时,触发临时表的添加记录事件,就将session值存入到临时表中
当session失效时,触发临时表的删除记录事件,给相应user的值从临时表中清除
这样用户在不同的地方登陆时,只需要将提交的用户名首先跟临时表中所存的进行逐个比较,如果没有相同的,再进入打开数据库核对输入的用户名和密码,存入session("user")
如果相同,则提示“此用户已在别处登陆”
试试看
talent303 2003-12-05
  • 打赏
  • 举报
回复
同意楼上的
Qthinker 2003-12-05
  • 打赏
  • 举报
回复
登陆页identify
<%@ Language=VBScript %>
<%
name = Request.Form("name")
passwd = Request.Form("passwd")
sql = "select name,passwd,type from usertype where name ='" & name & "'"
set conn = server.CreateObject("adodb.connection")
conn.Open Application("dsn")
set rs = server.CreateObject("adodb.recordset")
rs.Open sql,conn
if rs.EOF then
response.write "错误的用户名或密码!"
rs.Close
set rs = nothing
conn.Close
set conn = nothing
Response.End
end if

if not (rs("passwd") = passwd) then
response.write "错误的用户名或密码!"
rs.Close
set rs = nothing
conn.Close
set conn = nothing
Response.End
end if

session("username") = rs("name")
session("usertype") = rs("type")
rs.Close
set rs = nothing
sql = "update visit set visitnum = visitnum +1"
conn.Execute sql
conn.Close
set conn = nothing
Response.Redirect "frame.asp"
%>

在其他过页面加如
<%
if (isempty(session("username")) or len(session("username"))=0) then
Response.Redirect "error.asp"
end if
%>
whb147 2003-12-05
  • 打赏
  • 举报
回复
sessino_onstart 和session_onend
有时候不执行,这个不建议用,
还是建议用数据库,登陆为true,超时为false
foxty 2003-12-05
  • 打赏
  • 举报
回复
对,个人认为用APPLICATION的 sessino_onstart 和session_onend两个事件来解决问题就可以了。
byybyybyy 2003-12-05
  • 打赏
  • 举报
回复
仔细看一下application的用法,应该可以解决你的问题的
wangxjlb 2003-12-05
  • 打赏
  • 举报
回复
同意楼上的。
N1rvana 2003-12-05
  • 打赏
  • 举报
回复
使用数据库的方法,不妨再多建一个表[online],在表中存放登录用户的登录名、登录时间、最后活动时间。。。然后每次进行比较,设定一个超时时间(假设20分钟),如果用户的最后活动时间在20分以前,则从[online]中删除这个记录,这样下次就可以登录了。
beitou 2003-12-05
  • 打赏
  • 举报
回复
这个问题好象已经讨论过多次了,好象没有十全十美的办法。
shdfl 2003-12-05
  • 打赏
  • 举报
回复
可以用双重判断条件。
(1)用楼上的方法。
(2)再设置一个时间项,计算两次点击(或者登陆)之间的时间间隔。
如果再在COOKIES里加上判断码,综合起来判断就可以了。
zhuangbx220 2003-12-05
  • 打赏
  • 举报
回复
可是这系统不只一个用户啊,是多用户
pimple 2003-12-05
  • 打赏
  • 举报
回复
是的,我那个是错的..

不过用数据库的方法也会有同样问题...
clicknet 2003-12-05
  • 打赏
  • 举报
回复
这样不行,因为如果用户直接关闭浏览器的话会造成他下次无法登陆的.
pimple 2003-12-05
  • 打赏
  • 举报
回复
用APPLICATION

如果有用户连接APPLICATION=1
如果再有用户登录,检查APPLICATION是否=1如果是,返回错误信息.
加载更多回复(1)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧