 |
| ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 24th, 2005, 08:35 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Session Variable How To?
I want to be able to get to total time users spend on my site. I would like the read out to be in HH/MM/SS, hours/mins/secs. I know how to get it into my database. Thus far I am able to get ip address, browser type etc. But Server Variables don't help much with total time spent. How can I achieve this, I once explored using global.asa but I was told this was a wrong direction. What do I do.
|
|

August 24th, 2005, 08:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Didn't we discuss / start this here: http://p2p.wrox.com/topic.asp?TOPIC_ID=34146
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 24th, 2005, 08:44 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The above is way to vague. I need something more concrete.
|
|

August 24th, 2005, 08:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Then you could have answered "No" to the "Does this help?" question and ask for clarification..... ;)
But for a complete answer, you'll need to provide more details. In the other tread you said you wanted to track the main page but here you say you want to track the time spent on the site.
Which of the two is it? The latter can be tracked with the global.asa, although it won't be as specific to the second as you might think.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 24th, 2005, 09:02 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry about the mixup, I will be clear henceforth. I want the total time spent on the site (for now he he), not the total time spent on a particular page (like the main page), I want to be able to get the total time spent on my site in HOURS/MINS/SECS if possible. Once again sorry for the mixup.
|
|

August 24th, 2005, 09:18 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In that case, you *can* use Session_OnStart and Session_OnEnd.
Set a variable in Session_OnStart and give it the value of Now()
In Session_OnEnd define another variable and assign it Now() as well. Then subtract the two to get the total duration of the Session object. Notice I say duration of the Session object, not the time the user spent on the site. By default, a Session times out 20 minutes after the last page in the site was requested. There are situations where this isn't the case, for example when you have changed the timeout period, or explicitly ended a session with Session.Abandon. For a more detailed discussion about sessions, take a look here:
http://p2p.wrox.com/topic.asp?TOPIC_ID=1774
Another solution to time-tracking is to use code in every page in your site (possibly with an include file) that updates the "last request" time, e.g.:
Session("LastRequest") = Now()
Then in Session_OnEnd you can compare the start time with the last request and calculate the difference.
Concrete enough?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 24th, 2005, 10:17 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Appears to be concrete enough. If I get any trouble I will make a post, even if it works I will also post. Thanks.
|
|

August 24th, 2005, 10:41 AM
|
|
Authorized User
|
|
Join Date: Mar 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Its not working. This is my code for the global.asa
Code:
<script language="vbscript" runat="server">
sub Application_OnStart
end sub
sub Application_OnEnd
end sub
sub Session_OnStart
Session("start_time") = Now()
end sub
sub Session_OnEnd
Session("end_time") = Now()
Session("total_time") = Session("end_time") - Session("start_time")
end sub
</script>
When ever I print out the Session("total_time") i get a blank.
|
|

August 24th, 2005, 11:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think you should spend some time reading the thread I linked you to. I describes the behavior of Session_OnEnd.
In short, when the session ends, there is no longer a user attached to that process. It usually fires 20 minutes after the last request was made. This means you can't use variables declared in Session_OnEnd in your page, because there *is* no page / user associated with the event.
You could use the Session_OnEnd event to write to a database or text file to keep track of the time spent. Otherwise, if you want to display something like "You have been hanging around here for 20 minutes and 17 seconds" go for the other solution I suggested.
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Instant Street by dEUS (From the album: The Ideal Crash) What's This?
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| session and variable... |
badboy1 |
ASP.NET 3.5 Basics |
1 |
August 3rd, 2008 09:14 AM |
| Session Variable |
youyou_hym |
Dreamweaver (all versions) |
4 |
January 20th, 2005 11:48 AM |
| Session variable |
anuradha80 |
General .NET |
3 |
November 4th, 2004 12:39 AM |
| Session variable |
mrideout |
BOOK: Beginning ASP.NET 1.0 |
1 |
August 12th, 2004 07:01 PM |
| Session Variable |
mcdowell |
BOOK: Beginning ASP 3.0 |
5 |
June 20th, 2004 05:47 AM |
|
 |