Recommended: Several ways to call stored procedures with parameters Several ways ASP calls stored procedures with parameters1 This is also the easiest method, two input parameters, no return value: set connection = server.createobject(adodb.connection) connection.open someDSN Connection.Execute procname varvalue1, varvalue2 'Clear all objects as nothing, free up resources
There are two ways to implement this function:
1. Application
Use application object: If you are doing a large community, you may need to generate an application for each login id. Although the program design will be simpler, the login user is too many and it consumes server resources. It is never recommended here, because the application object is easy to generate when the user logs in, but to achieve the realization that the user exits the system and has not seen a better method yet~
The following is the quoted content: <% .....Get username username.... if Application(username)<> then response.write This user is already logged in response.end end if Application(username)=username ''Stored the user name of the user %> |
Add session oneend event to the global file, Application(isuserlogin)=false when offline
In addition, we need to detect whether the wire is suspended. There is a special method, which is an item in the server object
(See: http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=815)
2. Database asp
It may be more complicated to do, but it is suitable for systems with a large number of logged in users.
First, create a database for the user - use access to create a new onlyTOL8.mdb
Data Table 1: users store user registration information
Set the data table below: uID (auto numbering) userName (character type) userPass (character type)
Data Table 2: onlyLogin stores user temporary login information
The following data table is set: OLname (character type) OLtime (date type) OLip (character type)
After the database is built, add data manually to the users table userName table and add TOL8, add 111 to the userPass table.
Let’s do the user login interface below and copy the following code to save it into onlyLogin.asp file.
The following is the quoted content: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=gb2312> <title>Forbid login in different regions of the same account at the same time</title> </head> <body> <form name=form1 method=post action=loginPost.asp> Username: <input name=userName type=text id=userName size=15 maxlength=5> Password: <input name=userPass type=password id=userPass size=15 maxlength=15> <input type=submit name=Submit value=Login> </form> </body> </html> |
After completion, create a new loginCONN.asp file and copy the following code to save for connecting to the database.
The following is the quoted content: <% Dim CONN_TOL8 Dim Conn_T Dim mmdd mmdd=onlyTOL8.mdb Set CONN_TOL8 = Server.CreateObject(ADODB.Connection) Conn_T=Provider=Microsoft.Jet.OLEDB.4.0;Data Source= & Server.MapPath(&mmdd&) on error resume next CONN_TOL8.Open Conn_T %> |
The following is a loginPost.asp file that also exists in this directory. This is the key. Look at the following code carefully:
The following is the quoted content: <!--#include file=loginCONN.asp --> <% ''Delete the user that is active within maxTime time, maxTime has been defined in the loginCONN.asp file Conn_TOL8.Execute(Delete From onlyLogin where DATEDIFF(''s'',OLtime, now()) > & maxTime & ) ''=========================================================================================== Dim rs, ts, txt, sql, userName, userPass if Request.Form(Submit)=Login then userName=Request.Form(userName)''Get the form user login name userPass=Request.Form(userPass)''Get the form user login password ''Since we are not discussing security issues here, the user's password is not encrypted Set rs = Server.CreateObject(ADODB.RECORDSET) sql=SELECT * FROM users where userName = '' & userName & '' and userPass = '' & userPass & '' rs.Open sql, CONN_TOL8,1,1 IF not rs.eof then Call isOK(userName) '' The username and password are called correctly for the process, and isOK will be customized in the following program. else Response.Write(<a href=javascript:history.go(-1)>Unknown username or password</a>) Response.End() end if rs.Close Set rs=Nothing end if Sub isOK(userName) Dim Olip '' The IP saved by the current login username in the database Dim Oltime '' The last time the web page is refreshed saved by the current login username in the database is an important data to calculate whether the user is online. Dim OLip1 '' Record the current user login to the ip, which is used to distinguish whether it is the same user's label. OLip1=Request.ServerVariables(REMOTE_ADDR)''Get the IP of the user who submitted the login information Set ts=Conn_TOL8.execute(Select * FROM onlyLogin WHERE OLname=''& userName & '') if not ts.eof then '' Query the database whether this user has logged in information OLtime=ts(OLtime) OLip=ts(OLip) if OLip1<>OLip and DateDiff(s,OLtime,now()) < maxTime then ''The previous sentence determines that if the logged-in user ip is not the last recorded user ip in the database and ''The user's last activity time and current time interval does not exceed the specified number of seconds. Confirm that the user is currently online. Response.Write <a href=javascript:history.go(-1)>This user is currently online, you cannot log in to this account from other places! </a> Response.End() else '' Otherwise, it will be determined that the login will be successful and the value will be paid to the session Session(lgName)=userName Session(lgPass)=userPass Response.Redirect loginOK.asp Response.End end if else ''If the database has no login user record, execute the following statement Dim ls Set ls=Server.CreateObject(ADODB.RECORDSET) ls.OpenSelect * From onlyLogin,CONN_TOL8,2,2 ls.ADDNEW ls(OLname)=userName ls(OLip)=OLip1 ls(OLtime)=NOW() ls.UPDATE ls.Close Set ls=Nothing ''Resolution that login is successful and paid to session Session(lgName)=userName Session(lgPass)=userPass Response.Redirect loginOK.asp Response.End end if End Sub %> |
After logging in successfully, the leaves will jump to loginOK.asp
The following is the quoted content: <style type=text/css> <!-- body {background-color: #FF9900;} --> </style> <% IF Session(lgName)<> then %> You logged in successfully! ! ! Below is the iframe that sneaks into the web page to refresh the web page at the specified time to report to the server whether you are online or not. In order to facilitate distinction, we use white as the background color of the frame web page <iframe border=0 name=new_date marginwidth=0 framespacing=0 marginheight=0 src=loginFrame.asp frameborder=0 noResize width=100 scrolling=no height=30 vspale=0></iframe> <% else %> |
You are not logged in
The following is the quoted content: <% end if %> |
What to do next is loginFrame.asp
The following is the quoted content: <!--#include file=loginCONN.ASP --> <% CONN_TOL8.Execute(Update onlyLogin Set OLtime=''& NOW() & '' where OLname = '' & Session(lgName) & '') %> <html><head><meta http-equiv=refresh content=<%=(maxTime-5)%>; url=></head></html> |
So far the program is completed, and the key to this program is to determine whether the user is online.
Share: Implementation of Asp batch data entry Batch entry is widely used in databases, and there are many methods for batch entry. Next, I will talk about how I achieved it based on my actual application. The main use is the concept of form collection, which takes all the data in the collection through loop. Considering that it is convenient for everyone to see, I integrated it into one page. Below is the specific code