here's a good point of reference for ya:
http://www.w3schools.com/a
Main Topics
Browse All TopicsI want to include a global.asa file that reset the sesion to "" if the user does not click on the logout button. I have been told that this can be achieved by a global.asa file. Before i start showing the code can i have some input.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
here's a good point of reference for ya:
http://www.w3schools.com/a
I also have another question it relates to the one you answered before. If I restart the server and type in the url to search.asp, as the session = "" it redirects to login. If the user then logs in correctly and then clicks the logout link which runs this code:-
<%
Session.Abandon()
Session.Contents.RemoveAll
response.redirect("adminlo
%>
The user shouldn't then be able to view search.asp without logging in as i have printed the session to the screen in login and it is blank. However this isn't the case as the server some how is remembering the session and search can be viewed. Why is this and can this be prevented.
Using the code below stops the cache another EE expert got it.
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
However back to the global.asa file, i am finding it hard to sort . Basically all i need is for the session to be blanked if the user doesn't logout. The code below contains the functions i need but also extra coud you pull out the functions i need or explain each line.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
Application("visits")
Application("Active") = 0
' The connection string to the mdb.
Application("connString") = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\Inetpub\ww
End Sub
Sub Application_OnEnd
End Sub
Sub Session_OnStart
Session.Timeout = 20
Session("Start") = Now
Application.Lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.Unlock
Session("VisitorID") = intTotal_visitors
Application.Lock
Application("Active") = Application("Active") + 1
Application.Unlock
End Sub
Sub Session_OnEnd
set conn = Server.CreateObject ("ADODB.Connection")
conn.Open Application("connString")
Dim update__MMColParam
update__MMColParam = "1"
if (Session("MM_Username") <> "") then update__MMColParam = Session("MM_Username")
' Update the record when the user logout and write the logout time
' plus it sets the user as OFFLINE.
query = "UPDATE tblActiveusers SET LoggedOut= now() , Online=1 "
query = query & "WHERE Online=0 AND Username= '" + Replace(update__MMColParam
conn.Execute (query)
conn.Close
set conn = Nothing
Application.Lock
Application("Active") = Application("Active") - 1
Application.Unlock
End Sub
</script>
right in here:Sub Session_OnEnd
set conn = Server.CreateObject ("ADODB.Connection")
conn.Open Application("connString")
Dim update__MMColParam
update__MMColParam = "1"
if (Session("MM_Username") <> "") then update__MMColParam = Session("MM_Username")
' Update the record when the user logout and write the logout time
' plus it sets the user as OFFLINE.
query = "UPDATE tblActiveusers SET LoggedOut= now() , Online=1 "
query = query & "WHERE Online=0 AND Username= '" + Replace(update__MMColParam
conn.Execute (query)
conn.Close
set conn = Nothing
Application.Lock
Application("Active") = Application("Active") - 1
Application.Unlock
End Sub
you can put session("sessionname") = "", however, please keep in mind what I posted earlier about what happens if a user just goes to another page, or their computer crashes, etc...
in the Session_OnEnd. Looks like it is there to update a table with the logged out time of the user. It's your call to remove it or not, just keep in mind your application may be expecting a use for this, like some kind of report, or list of logged out users and the times they logged out at.
in the Application_OnStart section, the conn is set there so it can be readily available for all web applications on the server. While this is not the route I would do it, it is not a bad idea.
Would this work appart from the crashing.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
Session.Timeout = 20
Session("Start") = Now
Application.Lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.Unlock
Session("VisitorID") = intTotal_visitors
Application.Lock
Application("Active") = Application("Active") + 1
Application.Unlock
End Sub
session("sessionname") = "",
</script>
It would work, however, without:Application("connS
in it you will have to go through every one of your files, and make sure to update every instance of Application("connString"),
Also: You would need to do this
Sub Session_OnEnd
session("sessionname") = ""
Application.Lock
Application("Active") = Application("Active") - 1
Application.Unlock
End Sub
in order for that to work correctly, otherwise like it is is making session("sessionname") = "" all the time, which would is pointless to do, plus the Application("Active") would not be an accurate count with out it
In search the code is now:-
<!--#include file="global.asa"-->
<%
'Check if user is logged in
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
if Session("username") = "" then
'If not, go to login page
Response.Redirect("adminlo
else
%>
<html>
<Head>
<link href="css/css.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
div.test {
width: 500px;
height:300px;
margin-bottom: 0px;
margin-left: 10px;
margin-right: 10px;
}
#auto {
overflow: auto;
}
td {padding: 0px;}
-->
</STYLE>
</head>
<body bgcolor="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<body scroll="no" border="no" style="border-style: groove; border-width: 0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="856" height="428" border="1" align="center" cellpadding="0" cellspacing="" bordercolor="#ffffff">
<tr bordercolor="#FFFFFF">
<td height="64" colspan="5" align="left" valign="top" bordercolor="#990000" bgcolor="#990000"><img src="images/CFLogo.jpg" width="330" height="50">
<div align="center"></div></td>
<td width="31" rowspan="2" valign="bottom" bordercolor="#990000" bgcolor="#990000"> </
</tr>
<tr bordercolor="#FFFFFF">
<td width="349" align="center" valign="middle" bordercolor="#990000" bgcolor="#990000"><img src="images/admin.jpg" width="250" height="188">
</td>
<td height="300" colspan="4" align="center" valign="top" bordercolor="#FFFFFF" bgcolor="#000000">
<div align="center">
<h1><%Response.Write(Sessi
</div><DIV CLASS="test" ID="auto">
<FORM id=FORM1 name=FORM1 action="list.asp" method=post>
<P>
<TABLE cellSpacing=0 cellPadding=0 align=center bgColor=#000000 border=0>
<TR align="center">
<TD width="80"><font size=1 color=#ffffff>User Name</font></TD>
<TD width="80"><FONT size=1 color=#ffffff>Logged in</FONT></TD>
<TD width="80"><FONT size=1 color=#ffffff>IP Address</FONT></TD>
<TD width="80"><FONT size=1 color=#ffffff>Sort</FONT><
<TD colspan="2"> </TD>
</TR>
<TR align="center">
<TD> <INPUT style="WIDTH: 60px" width="60" id=text1 name=text1></TD>
<TD> <INPUT style="WIDTH: 60px" width="60" id=text2 name=text2></TD>
<TD> <INPUT style="WIDTH: 60px" width="60" id=text4 name=text4></TD>
<TD> <SELECT id=select1 name=Combo1>
<OPTION value=>User Name</OPTION>
<OPTION value=>Logged in</OPTION>
<OPTION value=>IP</OPTION>
</SELECT> </TD>
<TD width="80"> <INPUT style="WIDTH: 60px; color:#ffffff; BACKGROUND-COLOR: #990000" type=submit value=Search width="60" name=button></TD>
<TD width="80"> <INPUT style="WIDTH: 60px; color:#ffffff; BACKGROUND-COLOR: #990000" type=reset value=Clear width="60" name=button></TD>
</TR>
</TABLE>
</P>
</FORM>
</tr>
<tr bordercolor="#FFFFFF">
<td height="20" colspan="6" align="right" bordercolor="#990000" bgcolor="#990000">
<div align="right"><font color="#FFFFFF"><a href="logout.asp">Logout</
</tr>
</table></td>
</tr>
</table>
</body>
</html>
<%
end if
%>
In global.asa. the code is:-
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Session_OnStart
Session.Timeout = 1
Session("Start") = Now
Application.Lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.Unlock
Session("VisitorID") = intTotal_visitors
Application.Lock
Application("Active") = Application("Active") + 1
Application.Unlock
End Sub
Sub Session_OnEnd
session("sessionname") = ""
Application.Lock
Application("Active") = Application("Active") - 1
Application.Unlock
End Sub
the error is:-
Script error detected at line 26.
Source line: <%
Description: Expected statement
you will have to change session("sessionname") = "" to the session variable you wish to clear.
also:
Accepted Answer from kevp75
Date: 04/05/2006 09:21AM PDT
Grade: A
Accepted Answer
you can do this with a global.asa file
you would use something similar to this
Sub Session_OnEnd
session("sessionname") = ""
End Sub
now..there is a problem to this. Problem is, if the user closes the window, goes to another page, or their computer freezes on them, session("sessionname") will not get set to "" unless the session timeout occurs.
Best bet is to use some kind of javascript to detect if the user has clicked the X, or hit ALT-F4, then use some autoclosing popup to set session("sessionname") = ""
Or.....you could lower you session timeout in your server. Problem is with this is what if you have a user logged in to the site longer than your timeout.....
Personally, I wold nix the whole session variable idea, and just use cookies. if you set no expiry on the cookie, it is only valid until that user closes the browser. If security is an issue, set the cookie using some kind of encryption, and where you need to get the value from the cookie, decrypt it.
To set a cookie use:response.cookies("cook
to get a cookie use:variable = request.cookies("cookienam
HTAH
it could luke, but you also have to realize that you will need to make some serious changes to the application.
If I'm not mistaken you are building something to track your users?
in which case all that other stuff would have to stay, as it is what is going to be keeping count for you of who is logged in or out, and when they logged out and/or in.
Also, unless you change all your pages that reference Application("connString"),
everytime a person browses to your site, that file is run.
Yes you could put some code in a header.asp file to do the work you need it to do, but you would have to code it differently than what you have. but then you would have to go into every file and make sure it is included
do me a favor.put this in your page:
response.write("username")
and see what it puts out
The application tracks students. However it is only the admin who i want to have security. The student tracking just logs the students login time, user name and IP. The admin then logs in on a different login and can view these details. This all works but the admin needs to be secure. This is were the problem is if the admin doesn't log out and the sesion is stored a student could view th details.
ok, then take it out.
AS I SAID BEFORE:
without:Application("connS
in it you will have to go through every one of your files, and make sure to update every instance of Application("connString"),
AND:
now..there is a problem to this. Problem is, if the user closes the window, goes to another page, or their computer freezes on them, session("sessionname") will not get set to "" unless the session timeout occurs.
Best bet is to use some kind of javascript to detect if the user has clicked the X, or hit ALT-F4, then use some autoclosing popup to set session("sessionname") = ""
Or.....you could lower you session timeout in your server. Problem is with this is what if you have a user logged in to the site longer than your timeout.....
Personally, I wold nix the whole session variable idea, and just use cookies. if you set no expiry on the cookie, it is only valid until that user closes the browser. If security is an issue, set the cookie using some kind of encryption, and where you need to get the value from the cookie, decrypt it.
To set a cookie use:response.cookies("cook
to get a cookie use:variable = request.cookies("cookienam
that's probably your best bet., just go and replace:
session("username") = usersname '(setting the session variable)
with:
response.cookies("username
and where you would:
usersname = session("username") '(requesting the session variable)
replace it with:
usersname = request.cookies("username"
luke, there's someone I'm trying to help out here (http://www.experts-exchan
Business Accounts
Answer for Membership
by: kevp75Posted on 2006-04-05 at 09:21:47ID: 16383254
you can do this with a global.asa file
iename") = value e")
you would use something similar to this
Sub Session_OnEnd
session("sessionname") = ""
End Sub
now..there is a problem to this. Problem is, if the user closes the window, goes to another page, or their computer freezes on them, session("sessionname") will not get set to "" unless the session timeout occurs.
Best bet is to use some kind of javascript to detect if the user has clicked the X, or hit ALT-F4, then use some autoclosing popup to set session("sessionname") = ""
Or.....you could lower you session timeout in your server. Problem is with this is what if you have a user logged in to the site longer than your timeout.....
Personally, I wold nix the whole session variable idea, and just use cookies. if you set no expiry on the cookie, it is only valid until that user closes the browser. If security is an issue, set the cookie using some kind of encryption, and where you need to get the value from the cookie, decrypt it.
To set a cookie use:response.cookies("cook
to get a cookie use:variable = request.cookies("cookienam
HTAH