iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning ASP Course: Session - www.itechcollege.com ASP Course: Session - www.itechcollege.com
Online Degrees Scholarships & Fellowships Internships Student Financial Aid Study Abroad Itech Bookstore
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
ASP.NET
SQL
AJAX
FTP
XML
Career Center
Job List
Web Jobs
Student Jobs
Computer Jobs
Engineer Jobs
Developer Jobs
Job Search
Resume Writing
Job Interview
Salary Info


itech > courses > ASP > Session

Session

To set a session:

session("x") = "John"

"x" is sesseion's name, and "John" is session's value. You can replace them with anything.

To get a session:

response.write session("x")

If you already set a value "John" for the session, then the output is "John".

You can use session to track users. For example, you can set sessions in second.asp to track user name and password:

<%
u=request("user")
p=request("pass")

session("user")=u
session("pass")=p
%>

To protect a client page from other users, we can use Session and Redirect. Let's add two lines in second.asp and modify it as:

<%
u=request("user")
p=request("pass")

session("user")=u
session("pass")=p

if ((u="John") and (p="John123")) then
response.redirect "john.asp"
elseif ((u="Mike") and (p="Mike456")) then
response.redirect "mike.asp"
elseif ((u="Joe") and (p="Joe789")) then
response.redirect "joe.asp"
else response.write "<html><body>Sorry, invalid login</body></html>"
end if
%>

Let's modify john.asp. Add the following code on the top of the page:

<%
u=session("user")
p=session("pass")
if ((u="John") and (p="John123")) then

else
response.redirect "first.asp"
end if
%>

<html>
<body>
John's Web page.
</body>
</html>

The basic idea in the above session tracking is that, when an user enter an user name and a password in first.asp, the query strings are passed to second.asp where ASP sets session("user") and session("pass") with the value of the user name and password. The sessions can be retriaved in the following page john.asp. If in john.asp, you can get values of the session("user") and session("pass"), and the values match what you defined: "John" and "John123", then the page open, otherwise, you will be redirected to another page.

Test john.asp. Open a new web browser, typing: http://127.0.0.1/john.asp. Since there are no sessions of user name and password, the page will redirect you to first.asp. So as you can see, only the user who entered the correct user name and password can open the page.

  Back to Index Page
Next Page >>   Introduction
ASP Tags and Include File
Response and Request
If Then
For Loop
Redirect
Sessiont
Use Database
 

ASP Books
ASP Jobs



Bookmark:  del.icio.us digg facebook Reddit Mixx BlinkList Fark Furl NewsVine Simpy Spurl Segnalo Technorati blogmarks Google YahooMyWeb Windows Live



ASP Course: Session - www.itechcollege.com
Copyright ©2008, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech