Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variable Question

Status
Not open for further replies.

kaht

Programmer
Aug 18, 2003
4,156
US
I'm using a session variable to store a userid to be used in my application. The userid is pulled at the top of each page, like so:
Code:
var loggedIn = Session.Contents.Count;
if (!loggedIn) {
   Response.Write("<body style='background-color : #0000a0; color : #ffffff; font-size : 20pt; font-family : serif'>\n");
   Response.Write("<center><u>You cannot access this page.</u></center><br>\n");
   Response.Write("<center>Either your session timed out or you have not logged in.</center><br>\n");
   Response.Write("<center>To access Vacation Planner return to the Logon Screen</center><br>\n");
   Response.Write("<center><input type=button style='color : #FFFFFF;background-color: #0000A0; cursor : hand' onclick='javascript:window.location=\"login.html\";' value='Logon Screen'></center>\n");
   Response.Write("</body>");
   Response.End;
}
var userid = String(Session("userid"));
I had previously passed most of my information in a querystring (the page was imbedded in a frame so the querystring wasn't obviously noticed by the users) However, I wanted to set it up with a session variable so that users wouldn't be able to figure out how to manipulate the querystring and get into pages they don't have access to. The first check is to count the session variables to make sure that the users have indeed logged in and a session variable exists. This works fine..... until a user gets up and walks away from the machine for 30 mins. At this time the session variable seems to time out and lose it's value, however Session.Contents.Count does not decrease itself by one when the value times out. So, even though a value doesn't exist for userid, the initial check isn't evaluated correctly, and all SQL queries ran for my userid have a value of "undefined". I know instead of checking Session.Contents.Count I could check to see if (userid == "undefined") after the value is pulled, but is there a better way to do this?

I'm using server side JScript by the way.... not VBScript.

-kaht

banghead.gif
 
You could use a keep alive page

which keeps your sessions alive until they really end the session

well, you will have to use frames...

but that's not a real setback

just define a topframe and mainframe...

Define the frameset where the topframe has 0 space

in the top you put a page which this contents:

<html>
<head>
<script>
var tHandle;"
function StartTimeInterval(){"
tHandle = setInterval("location = location", 10000)
}
function StopTimeInterval(){
clearInterval(tHandle);
}
</SCRIPT>
</HEAD>
<BODY onload="StartTimeInterval()" onunload="StopTimeInterval()">
</BODY></HTML>


The rest in your mainframe
 
Toeter, thanks for the reply, but I figured out a way to check for session variable existence another way. Ends up the problem I was having wasn't exactly what I thought it was... Checking for variables that don't exist in vbscript is sooo easy using the Nothing reference. They really need to make an equivalent for JScript.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top