&&&&&一个老问题--没找到答案--关于限制的问题---

offerking 2003-09-20 05:28:58
如何限制同一个帐号在同一时间只能登陆一个?
我搜索了以前的帖子,好象没有找到好的办法....

想实现这样的效果,只要一个帐号在线,别人用同一个帐号就不可以登陆,这个帐号不管是正常退出还是非正常(如直接关闭窗口..断电..等)退出,只要是不在线了,用这个帐号就可以登陆。
比如在这个电脑上把这个网站的所有窗口给关闭了,则这个帐号就可以登陆...

我看网上银行(如招商银行)做的和这个效果一样,他们可能用的是软件之类的东西,ASP能实现类似的效果吗?

谢谢~~!!!
...全文
56 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zerokings 2003-09-21
  • 打赏
  • 举报
回复
谢谢各位,我试一试...

最难做的就是异常退出的情况..
超级大笨狼 2003-09-21
  • 打赏
  • 举报
回复
Session结合数据库,一般这么做,不过Session事件不保准,好多人来这里问这个问题,你搜索以前别人的问题吧
超级大笨狼 2003-09-21
  • 打赏
  • 举报
回复
Session_OnEnd
The Session_OnEnd event occurs when a session is abandoned or times out. Of the server built-in objects, only the Application, Server, and Session objects are available.

Syntax
<SCRIPT LANGUAGE=ScriptLanguage RUNAT=Server>
Sub Session_OnEnd
. . .
End Sub

</SCRIPT>

Parameters
ScriptLanguage
Specifies the scripting language used to write the event script. It may be any supported scripting language, such as VBScript or JScript. If more than one event uses the same scripting language, they can be combined under a single set of <SCRIPT> tags.
Remarks
You cannot call the MapPath method in the Session_OnEnd script.

See Also
Session_OnStart, Application_OnEnd


超级大笨狼 2003-09-21
  • 打赏
  • 举报
回复
Session Object
You can use the Session object to store information needed for a particular user-session. Variables stored in the Session object are not discarded when the user jumps between pages in the application; instead, these variables persist for the entire user-session.

The Web server automatically creates a Session object when a Web page from the application is requested by a user who does not already have a session. The server destroys the Session object when the session expires or is abandoned.

One common use for the Session object is to store user preferences. For example, if a user indicates that they prefer not to view graphics, you could store that information in the Session object. For more information on using the Session object, see Managing Sessions in the ASP Applications section.

Note Session state is only maintained for browsers that support cookies.

Syntax
Session.collection|property|method

Collections
Contents Contains the items that you have added to the session with script commands.
StaticObjects Contains the objects created with the <OBJECT> tag and given session scope.


Properties
CodePage The codepage that will be used for symbol mapping.
LCID The locale identifier.
SessionID Returns the session identification for this user.
Timeout The timeout period for the session state for this application, in minutes.


Methods
Abandon This method destroys a Session object and releases its resources.


Events
Scripts for the following events are declared in the global.asa file.

Session_OnEnd
Session_OnStart


For more information about these events and the global.asa file, see the Global.asa Reference.

Remarks
You can store values in the Session object. Information stored in the Session object is available throughout the session and has session scope. The following script demonstrates storage of two types of variables.

<%
Session("username") = "Janine"
Session("age") = 24
%>

However, if you store an object in the Session object and use VBScript as your primary scripting language, you must use the Set keyword. This is illustrated in the following script.

<% Set Session("Obj1") = Server.CreateObject("MyComponent.class1") %>

You can then call the methods and properties exposed by MyComponent.class1 on subsequent Web pages, by using the following.

<% Session("Obj1").MyMethod %>

Or by extracting a local copy of the object and using the following.

<%
Set MyLocalObj1 = Session("Obj1")
MyLocalObj1.MyObjMethod
%>

Another way to create objects with session scope is to use the <OBJECT> tags in the global.asa file.

You cannot, however, store a built-in object in a Session object. For example, each of the following lines would return an error.

<%
Set Session("var1") = Session
Set Session("var2") = Request
Set Session("var3") = Response
Set Session("var4") = Server
Set Session("var5") = Application
%>

Before you store an object in the Session object, you should know what threading model it uses. Only objects marked as both can be stored in the Session object without locking the session to a single thread. For more information, seeSelecting a Threading Model inCreating Components for ASP.

If you store an array in a Session object, you should not attempt to alter the elements of the stored array directly. For example, the following script will not work.

<% Session("StoredArray")(3) = "new value" %>

This is because the Session object is implemented as a collection. The array element StoredArray(3) does not receive the new value. Instead, the value is indexed into the collection, overwriting any information stored at that location.

It is strongly recommended that if you store an array in the Session object, you retrieve a copy of the array before retrieving or changing any of the elements of the array. When you are done with the array, you should store the array in the Session object all over again so that any changes you made are saved. This is demonstrated in the following example.

---file1.asp---
<%
'Creating and initializing the array
Dim MyArray()
Redim MyArray(5)
MyArray(0) = "hello"
MyArray(1) = "some other string"

'Storing the array in the Session object
Session("StoredArray") = MyArray

Response.Redirect("file2.asp")
%>

---file2.asp---
<%
'Retrieving the array from the Session Object
'and modifying its second element
LocalArray = Session("StoredArray")
LocalArray(1) = " there"

'printing out the string "hello there"
Response.Write(LocalArray(0)&LocalArray(1))

'Re-storing the array in the Session object
'This overwrites the values in StoredArray with the new values
Session("StoredArray") = LocalArray
%>

Examples
The following code assigns the string MyName to a session variable called name, assigns a value to a session variable called year, and assigns an instance of the some.Obj component to a variable called myObj.

Session("name") = "MyName"
Session("year") = 96
Set Session("myObj") = Server.CreateObject("someObj")
%>


BainStudio 2003-09-20
  • 打赏
  • 举报
回复
除了上面所说的方法.还有可以通过数据库来实现.如果用户登录系统就添加一个字段到一个表中,如果多少时间没有活动就删除.视为超时.

当用户登录系统时,就先对该表进行搜索.如果有重复的.提示错误信息.没有,通过.
liudong963 2003-09-20
  • 打赏
  • 举报
回复
<%
Sub Application_OnStart
Application("OnLineUserID")=","
End Sub
Sub Session_OnEnd
'一个用户退出,就删除其在线公共变量中的用户ID
Application.Lock
Application("OnLineUserID")=Replace(Application("OnLineUserID"),",用户ID,",",")
Application.UnLock
End Sub
%>
把上面程序放在web根目录下的Global.asa文件中(注意,一定要是根目录)

把下面程序放在登录检测文件中,并根据函数功能进行检验
<%
'判断根据用户ID能否登录的函数,如果用户帐号不在线就返回ture,同时设置了用户在线信息
Function CanBeLogon(userID)
Dim OnLineUser
Application.Lock

OnLineUser=Application("OnLineUserID")
If InStr(OnLineUser,","&userID&",")>0 Then
CanBeLogon=False
Else
Application("OnLineUserID")=OnLineUser&userID&","
CanBeLogon=True
End If

Application.UnLock
End Function
%>
offerking 2003-09-20
  • 打赏
  • 举报
回复
自己顶一下........
offerking 2003-09-20
  • 打赏
  • 举报
回复
能具体说一下吗?
谢谢~~~~
ChinaOk 2003-09-20
  • 打赏
  • 举报
回复
可以啊.
只要你的服务器支持sessionout事件

28,406

社区成员

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

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