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
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

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


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech