ASP Forms - How to Store Sessions and Retrieve Them
(Page 5 of 5 )
You store variables in your session object. For instance, let's say we wanted to store the user's name in an object. Here is how we would do that:
<%
Session("name")="Michael Bolton!"
Session("music")="Horrible"
%>
Now that the variables are stored in the session object, we can use them for any page within our application. If we wanted to display a greeting on our home page, we could do so by inserting the following code on the page:
Greetings <%Response.Write(Session("name"))%>
Your music is <%Response.Write(Session("music"))%>
This would result in the following being displayed in the user's browser:
Greetings Michael Bolton!
Your music is Horrible
Well, we covered a lot of ground in this article, and there is still a lot more to discuss with sessions and cookies, but that will have to wait for next time. In our next article, we will continue our discussion of sessions, and cover applications as well.
Till then...
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |