ASP programming introduction (eight)

xiaoxiao2021-03-06  41

Author: cnbruce posted from: 5D multimedia objects in addition to ASP for sending (Response), to receive and process data (requeest), access server (Server) object, there are some very practical mark Active Server application (Application) And a single user information (session) object. Session object This object accounts for considerable proportion in ASP. Since the web page is a stateless program, the user browsing status cannot be known. In ASP, the user's private data variable is recorded by the session object, and the user will not confirm as the user again, and the user jumps between the user's web page, there will be no disappearance. . These are really important, especially if there is a member's system must be used. Like the membership login account, time, status, and many real-time data that are many recorded (such as the shopping system record the user's shopping basket), these information belongs to the private needs of each user, usually developers are used. Session recording. The session in the ASP is composed of cookies, the server records the data recorded in all sess, and is transmitted to the user's browser in a cookies. Usually, the general browser will save these cookies, whenever the user is selected, the browser will return these cookies back to the Server to process: this is the operation principle of the session. This findings that session SESSION is only kept in a browser that supports cookies. If the customer closes the cookie option session, it cannot work. First, the session.SessionId sessionID property returns the user's session ID. When you create a session, the server generates a separate identifier for each session, and the session ID returns in a long plastic data type. In many cases, SessionID can be used for web page registration statistics. Using this property can solve a control problem for users. The main function of this problem is that a module for a website, when a member is logging in, another person is logged in with the same member name, and cannot browse this module: that is, a member name is only Can browse this module alone. Control is implemented by using the member name (assuming to userid, unique) and sessionid. When a member logs in, a session login status is sent to this member such as: session ("status") = "logged", and writes the session.SessionID of this member to the database. When he wants to browse this module, first determine whether it is logged in, if it has been logged in, it is determined whether it is the same as the database record, if it is different, if it is different, it cannot be accessed. Thus, when another user logs in with the same member name, then recorded in the database is the new sessionID, and the former cannot pass the inspection when accessing this module. This realizes a member name to browse a module alone at the same time. This feature has a special role in some toll websites, which prevents a member named many people to browse, and protect the company for the company. <% = Session.SessionID%> is a unique ID identifier generated separately, brushing new debugging. Second, session.timeout This property sets the maximum interval of the SESSION. The interval means that the client side has requested the request from the last time to the web server, and ask the time to ask the web server next time.

It can be understood that the session will terminate if the user does not refresh or request a web page within the timeout time limit. The Timeout property is in minutes, specifying a timeout time limit for the application's session object, generally default for 20 minutes. This is more important when logging in to the personal information page and forgets the window when you log in to your personal information page, which is more important (at least time to set the time). <% = Session.timeout = 10%> The above sessionID, Timeout belongs to two properties of the session object, and see a method of this object Abandon 3, session.abandon This method is the only way for the session object, you can clear the session object, use To eliminate the user's session object and release the resources they occupy. Of course, if you don't have a clear call Aandon method, once the session is timeout, the server will also delete these objects and release resources. Below you will know the program of the session object and the use of the Abandon method. 1. Login.asp <% 'is whether the value of the variable loginout in the URL is TRUE. If it is true, it will execute session.abandon (). If Request.QueryString ("loginout") = "true" the session.abandon () end if 'only if you click on the Submit button, it is not empty, and the session object is established. Submitname = Request.form ("Submit1") if Submitname = "Submit" Then if Request.form ("Name") <> "" And Request.form ("PWD") <> "" "" ") = Request.form ("Name") Session ("PW") = Request.form ("PWD") end ifnd IF%> <% 'If session ("name" is not empty, display session ("name" The value and make a link to INFO.ASP. If session ("name") <> "" "" Your Name value is: "& session (" name ") Response.write ("
Show you Information ") Else 'Otherwise, the session (" Name ") does not exist, then the display form is used to enter a platform for establishing the session.

%>

Name:
password:
Show your information <% end if%> Note SESSION ("Name" is empty and not empty, do one to INFO. ASP's link, how the specific debug results, then see INFO.ASP content. 2. Info.asp <% 'If the session object value jumps to login.aspif sessions ("name") = "" "" Login.asp ") 4. If you show your personal information else response.write ( "Your Name:" & Session ("Name") & "
") Response.write ("Your Password:" & Session ("PW") & "
") end if%> Return Exit It can be seen that the display of Info.asp page is actually required. That is, there must be a session value to exist, so that the specific information can be displayed. This is more useful in the login system. You can imagine login.asp into a login window, of course, this is relatively simple (just if you enter the name and password), the actual situation is: Judging whether the input usage and password are consistent with the name and password in the database. If the correct anastomosis generates session. However, the role of Info.asp page can just be a permission page, because it requires sessions to enter the page, and the generation of Session is to ensure proper password. So when the form window appears at first, you can't open the login.asp link, only when the form is submitted to generate session before entering. This is the essence of the login system, do you know? :) Four, session_onstart session_onstart belongs to a class of events for the session object. It happens when the server creates a new session. The server handles the script before performing the requested page. The session_onstart event is the best time to set the session period, as you will set them before accessing any pages. The object's routine triggers the session_onstart event when starting, and then runs the process of the session_onstart event.

转载请注明原文地址:https://www.9cbs.com/read-71600.html

New Post(0)