Author |
Topic |
The Impact
Junior Member
Australia
398 Posts |
Posted - 29 September 2003 : 00:45:09
|
Hey, it looks like it's working !
Did you change it or did it work it's self out in time ?
Good effort on the forums, they look great ! |
|
|
NiteOwl
Junior Member
Canada
403 Posts |
Posted - 29 September 2003 : 00:54:47
|
Thanks The Impact, as you can see we are a fairly popular place what with contracts and stuff coming about, we are also just one month old. I did make a change, the code looks like the last posting I did, I am not certain its quite right but, I am watching! I would never have gotten this far without your help, even if there is a bit of tweaking I am very pleased with what I have so far.
I am waiting to see if the active users drops off, its almost been 20 minutes. |
-=NiteOwl=-
|
Edited by - NiteOwl on 29 September 2003 00:56:29 |
|
|
The Impact
Junior Member
Australia
398 Posts |
Posted - 29 September 2003 : 00:59:37
|
The last change must have fixed it then.
If your ever worried that it isn't working properly backup your global.asa and try changing the code.
There are lots of people on this forum who will be happy to help out if you come across any problems. |
|
|
laser
Advanced Member
Australia
3859 Posts |
Posted - 29 September 2003 : 01:46:08
|
Seems to be working fine now, but I still don't understand the use of TodaysDate2 different from TodaysDate, but working is the main thing |
|
|
laser
Advanced Member
Australia
3859 Posts |
Posted - 30 September 2003 : 00:16:38
|
Just some thoughts if you want to streamline that code .... cutting out the lines I want to ignore (but keep them in your code ) you have :
Application("TodaysDate2") = DateAdd("h",3,vbShortDate)
.
.
.
if Application("TodaysDate2") = DateAdd("h",3,vbShortDate) then
Application("VisitorsToday") = Application("VisitorsToday") + 1
else
Application("TodaysDate") = Date
Application("TodaysDate2") = DateAdd("h",3,vbShortDate)
Application("VisitorsToday") = 1
end if
Now won't the condition always be TRUE ? Thus, the THEN will be executed, and never the ELSE.
Also, there's a lot of 3's embedded in the code, probably better to define a variable/constant at the top (maybe called timeoffset) then set that to 3. This will ease your pain if you ever move server's from the timezone your server is currently in - trust me, it does happen sometimes |
|
|
NiteOwl
Junior Member
Canada
403 Posts |
Posted - 30 September 2003 : 09:31:47
|
can you give me an example of your thoughts? |
-=NiteOwl=-
|
Edited by - NiteOwl on 05 October 2003 14:18:06 |
|
|
laser
Advanced Member
Australia
3859 Posts |
Posted - 30 September 2003 : 19:41:46
|
quote: As for the variable constant, can you give me an example of your thoughts?
Sure, to make your code more 'elegant' you declare a constant (although I can't find the syntax now), so I mean like :
Dim timediff timediff = -3
then throughout your code replace all your -3's with timediff. |
|
|
NiteOwl
Junior Member
Canada
403 Posts |
Posted - 30 September 2003 : 21:44:17
|
Application("ActiveUsers") = 0 Application("HighestToDate") = 0 Application("TodaysDate") = DateAdd("h",timeset,vbShortDate) Application("VisitorsToday") = 0 End Sub ==============CUT to save space=======
So I have a new wish!!
In green above I have highlighted the number 0, I see that if my server ever reboots the code will automatically force my number back to zero and i lose my history of the highest number of hits to the site.
So, would there be a way to read/write to a file or something to retain the last value incase the server re-boots, also can the file be created if it does not exist from a GLOBAL.ASA I realize the global is limited. |
-=NiteOwl=-
|
Edited by - NiteOwl on 05 October 2003 14:16:46 |
|
|
laser
Advanced Member
Australia
3859 Posts |
Posted - 30 September 2003 : 21:50:30
|
Even if it can't be created, you can manually create the file and use it from there to read/write to. |
|
|
NiteOwl
Junior Member
Canada
403 Posts |
Posted - 12 October 2003 : 16:35:10
|
Update: I have been testing and working on this for some time now, Boy Do I timezones and anything to do with time. :)
Anyway the vbShortDate scripts within the global do NOT work as one would expect. Since some foks maybe following these posted I wanted to set the story straight and to post the working solutions.
Solution1: for a server located in the same timezone as that of the majority of users. In other words you do not have any corrections for time zone to perform on your output-ed data.
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
'################## START Snitz Active Users Lite ######################################
Sub Application_OnStart
Application("ActiveUsers") = 0
Application("HighestToDate") = 0
Application("TodaysDate") = Date
Application("VisitorsToday") = 0
End Sub
Sub Session_OnStart
Session.Timeout = 20 '## minutes
Session("Start") = Now
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
if Application("ActiveUsers") > Application("HighestToDate") then
Application("HighestToDate") = Application("HighestToDate") + 1
end if
if Application("TodaysDate") = Date then
Application("VisitorsToday") = Application("VisitorsToday") + 1
else
Application("TodaysDate") = Date
Application("VisitorsToday") = 1
end if
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
'################## End Snitz Active Users Lite ######################################
</SCRIPT>
Solution2: for a server (in this case 3 hours ahead of me) and you need to make a time corrections, the only way I was able to do this in the global.asa file was to actually write to a separate file and then do a calculation and run a process once the desired time was reached.
<script language="VBScript" runat="Server">
'################## START Snitz Active Users Lite ###################################
'###############################################################################
'## Edited by NiteOwl
'## File name is Global.asa to be located in the ROOT of your web
'## to be used with the Active-Users application
'################################################################################
'## Default of this program is running on a server located 3 hours ahead of me.
'## This is changed with the file named last-update.txt The text file needs to
'## have one default entry of (in my case)
'## 10/13/2003 02:58:00 AM
'## The script checks this date, compares it to see if its >24hrs and if so
'## overwrites the current entry in the txt file with the current date and time and
'## also runs whatever process I have specified. If the date and time is not yet due
'## the process continues to check.
'################################################################################
Sub Application_OnStart()
Application("SessionCount") = 0
Application("ActiveUsers") = 0
Application("HighestToDate") = 0
Application("VisitorsToday") = 0
End Sub
Sub Session_OnStart()
Session.Timeout = 20 '## minutes
Session("Start") = Now
Application.Lock
Application("SessionCount") = Application("SessionCount") + 1
Application("ActiveUsers") = Application("ActiveUsers") + 1
if Application("ActiveUsers") > Application("HighestToDate") then
Application("HighestToDate") = Application("HighestToDate") + 1
end if
Application("VisitorsToday") = Application("VisitorsToday") + 1
Application.UnLock
'## Check the file every 5 visits cuts down on server resource's
'## you can increase or decrease this depending on the activity tou your web.
if Application("SessionCount") > 5 Then
Application.Lock
Application("SessionCount") = 0
Application.Unlock
Set ObjMyFile = CreateObject("Scripting.FileSystemObject")
Set OpenMyFile = ObjMyFile.OpenTextFile(Server.MapPath("last-update.txt"))
MyFileValue = OpenMyFile.ReadLine
OpenMyFile.Close
'## the date in the last-update.txt file must be greater than 24 hours
if DateDiff("h",MyFileValue,NOW) > 24 Then
Application.lock
'#### Insert Apps you want to Run
Application("VisitorsToday") = 1
'#### Insert Apps you want to Run
Application.Unlock
Set WriteMyFile = ObjMyFile.CreateTextFile(Server.MapPath("last-update.txt"))
WriteMyFile.WriteLine(NOW)
WriteMyFile.Close
end if
end if
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
'################## End Snitz Active Users Lite ######################################
</SCRIPT>
Edited: October 12, 2003 Link to the working ActiveUsersLite |
-=NiteOwl=-
|
Edited by - NiteOwl on 12 October 2003 19:32:06 |
|
|
Topic |
|