What is session? Simply put, it is the number that the server sends to the client. When a www server is running, several users may browse the website running on this server. When a user establishes a connection with the www server for the first time, the user establishes a session with the server, and the server automatically assigns a sessionid to the user to identify the unique identity. This sessionid is a random string consisting of 24 characters on the www server. We will see it in the following experiment.
This unique sessionid has great practical significance. When a user submits a form, the browser automatically attaches the user's sessionid to the http header information (this is an automatic function of the browser and the user will not notice it ), after the server processes the form, it returns the result to the user corresponding to the sessionid. Imagine how the server knows which user submitted the form when two users register simultaneously without sessionid. Of course, sessionid has many other functions, which we will mention later.
In addition to sessionid, each session contains many other information. However, for programming asp or asp.net, the most useful thing is to access the built-in session object of asp/asp.net to store their own information for each user. For example, if we want to know how many pages a user visits our website browses, we may add the following to each page that a user may access:
Program code:
<%
If session ("pageviewed") = "" then
Session ("pageviewed") = 1
Else
Session ("pageviewed") = session ("pageviewed") + 1
End if
%>
You can use the following sentence to learn about several pages you have browsed:
Program code:
<%
Response. write ("you have viewed" & session ("pageviewed") & "pages ")
%>