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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling session variable

Status
Not open for further replies.

lynque

IS-IT--Management
Sep 30, 2004
124
CA
I have started session("visitorID") in global.asa in order
to keep track of how many users are on our site at any
given time, trouble is I can't seem to call the session
while on another page.

As I am relatively new to asp I'll post both the setting
of the session and the call to it on the other page below

any and all help is appreciated.

Global.asa reads:

Sub Session_OnStart
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

Search.asp reads:

<td width="128" valign="top" align="center">
There are
<%
Response.Write(Session("VisitorID"))
%>
active connections.
</td>

Just because you can, it doesn't mean you should
 
hi

This is what I have to do the same.

Code:
<script language="vbscript" runat="server">

	Sub Application_OnStart
	
	  ' Set our user count to 0 when we start the server
		Application("ActiveUsers") = 0
	

' Count Active Users
'-----------------------------------------------	
	Sub Session_OnStart
	  ' Session Timeout currently 30 mins
		Session.Timeout = 30
	  ' Set a Session Start Time
	    Session("Start") = Now
	  ' Increase the active visitors count when we start the session
		Application.Lock
		Application("ActiveUsers") = Application("ActiveUsers") + 1
		Application.UnLock
	End Sub

Sub Session_OnEnd
	 ' Decrease the active visitors count when the session ends.
		Application.Lock
		Application("ActiveUsers") = Application("ActiveUsers") - 1
		Application.UnLock
End Sub
'------------------------------------------------
</script>

Then it is called as follows

Code:
 Response.Write("<p>Number of Current Sessions: "& Application("ActiveUsers")&"</p>")

Hope this helps.

NOTE that I reference the variable as 'Application' and not 'Session' as it is an application variable as aposed to a session variable.

Thanks

Glen
Conception | Execution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top