View Full Version : admin page
pinkcat_02
04-16-2003, 04:31 PM
I was wondering how to allow one user at a time that can do any changes on the database through the admin site.
With a login screen it can be possible that many user accessing the same data at the same time which is against redundancy...
Any ideas?
Thanks
Spudhead
04-16-2003, 04:45 PM
The application object might be useful. You could use that to track how many users are logged in. Although I'm not sure what you mean by "against redundancy".
pinkcat_02
04-16-2003, 04:47 PM
well i meant like if one of them is trying to edit a data and the other is trying to delete the same data at the same time.
Do u have any examples of application object as I have never used it.
Thanks
david7777
04-17-2003, 08:55 AM
If you want to do it with the application, make a file called global.asa with the following in it: (put the file in the root directory)
<script language="vbscript" runat="server">
Sub Application_OnStart
Application.Lock
Application("currentAdminUsers") = 0
Application.UnLock
End Sub
Sub Session_OnStart
Application.Lock
Application("CurUsers")=Application("CurUsers")+1
Application.UnLock
End Sub
Sub Session_OnEnd
Application.Lock
Application("CurUsers")=Application("CurUsers")-1
Application.UnLock
End Sub
Sub Application_OnEnd
End Sub
</script>
Then in your ASP page, when a user tries to login to admin, after the password check, put the following code:
if Application("currentAdminUsers") > 0 then
' Deny access because there is already a user logged in
else
' Grant access
' Increment number of logged on admin users by one:
Application.Lock
Application("currentAdminUsers") = Application("currentAdminUsers") + 1
Application.UnLock
endif
Then dont forget to add the following to the logoff code:
Application.Lock
Application("currentAdminUsers") = Application("currentAdminUsers") - 1
if Application("currentAdminUsers") < 0 then
Application("currentAdminUsers") = 0
endif
Application.UnLock
Hope this helped
:cool:
Good code from david7777.
I suspect some problems though. What if the session times out? So you need some code in the session_onend sub to. + you'll need an extra sessionvariable that identifyes the session as an admin-session (since you probably will have these admin-pages in the same virtual directory as you site) and only subtracts 1 from the Application("currentAdminUsers") on logout or timout.
what's more, why try to fix this at the application tier. Isn't it simpler to lock the tables when the sql statements are executed? + each time you run a query, check the number of updated, inserted, deleted records?
david7777
04-17-2003, 01:20 PM
Thanx raf - i forgot about that ;)
raf is right though - locking the tables and checking the number of records edited/deleted/inserted would be the best way - that enables multiple admin users at a time, but prevents things going wrong...
pinkcat_02
04-17-2003, 02:07 PM
And can you please explain me how to lock the tables and checking the number of datas?
Thanks
allida77
04-17-2003, 02:16 PM
What kind of db are you using?
pinkcat_02
04-17-2003, 02:27 PM
Microsoft Access
locking:
what db-format do you use?
sqlserver will, like most db-formats, do this automatically. http://www.developerfusion.com/show/1688
oracle even has rowlevel locking.
number updated/deleted/inserted:
just add this as a parameter yo the execute command. like
dim numberinserted, sql
sql = INSERT ....
conadmin.Execute sql,numberinserted
response.write(numberinserted)
nothing more to it then that. doesn't allways have to be that hard. :)
Posts crossed.
Here's some info on locktypes
http://www.garymgordon.com/misc/asp/Tutorials/cursor.pdf
(Let me note that access is not the most ideal multiple user db. but upuntil 20 simultanious users, it'll do, i suppose)
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.