Click to See Complete Forum and Search --> : global.asa problem


ozpo1
03-09-2006, 06:12 PM
<script language="vbscript" runat="server">
Hi, I created some variables to count the entries to my website.
Everything work right and it count as it should. But once in a while, all the variables together turning into 0 again. I asked my host and they told me the server was fine all the time today, so what else could cause it? why are they turning into 0 once in a while.

p.s- I also had a few files today that led to internal server errors when I called a certain page, can that be the reason? Thanks in advanced, Oz.


Sub Application_OnStart
Application("Home")=0
Application("aboutus")=0
Application("faq")=0
Application("sitemap")=0
Application("directory")=0
Application("questionary")=0
Application("finalStep")=0
Application("homeHC")=0
Application("homeAC")=0
Application("joinus")=0
Application("nocontractor")=0
Application("present")=0
End Sub
</script>

JayM
03-09-2006, 06:54 PM
It should be something like this:


Sub Application_OnStart
Application("visits") = 0
End Sub

Sub Application_OnEnd

End Sub

Sub Session_OnStart
Application.lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.unlock

End Sub

Sub Session_OnEnd

End Sub


Cheers

ozpo1
03-09-2006, 08:16 PM
I'm not trying to count the number of the users, I'm trying to count the number of user per page and this is why I make my count on each page.

In any case, my question was why does my variables are turnning into 0 once in while. Can someone help me with that?

JayM
03-09-2006, 08:43 PM
You would have to post your entire script please. What you provided does not tell us much.

ozpo1
03-10-2006, 12:58 PM
This is my global.asa file:
<script language="vbscript" runat="server">

Sub Application_OnStart
Application("Home")=0
Application("aboutus")=0
Application("faq")=0
Application("sitemap")=0
Application("directory")=0
Application("questionary")=0
Application("finalStep")=0
Application("homeHC")=0
Application("homeAC")=0
Application("joinus")=0
Application("nocontractor")=0
Application("present")=0
End Sub
</script>


This is the ASP code that I added to each of my pages to count the clicks per page, In this case the variable is the home-page counter:
<%
Application("Home")=Application("Home")+1
%>

The rest of the code is html.

Thanks again, Oz.

ahmed1
03-16-2006, 01:27 AM
Hey try to initialize all variables befofe
Sub Application_OnStart
and tell me it works or not

ozpo1
03-16-2006, 10:10 PM
It's initialize the variables. It's cause them to be parmanent zero.
For now I just uploaded a gloabl file that doesn't have anything in the onstart, and hence I don't have any problems any more. Thanks,Oz.

ahmed1
03-18-2006, 04:42 AM
make a page named as pagecounter.asp

<%
Session("Home")=0
Session("Aboutus")=0
Session("faq")=0
%>
All pages you want to calculate the number of visits
Then open the home page
and type it in home page
<% Session("Home")=Session("Home") %>
Every time 1 will add to this session variable when the page is visited
and do the same job on every relevent page
like
in your aboutus.asp
<% Session("Aboutus")=Session("Aboutus")+1 %>
and so on
make a third page sitestat.asp
Then entere the code
The home page is visited <% =Session("Home") %>
The about us page is visited <% =Session("aboutus") %>
for all pages
try it and tell me it works or not

Ribeyed
03-18-2006, 07:48 PM
How often is once in a while?
Every time the web server is rebooted after updates and patches your application variables will default back to zero. You need to have either a text file, database or some other place to store your application variables values then pull these values back out when the application restarts.

ozpo1
03-19-2006, 12:08 PM
First to ahmed1:
What you suggested is to use Session variables, and it's not going to work, because it's get the value of Zero every time a session is started, and the the values are not kept.

ozpo1
03-19-2006, 12:09 PM
I guess that's the only way.
I will try and will update it here, Thanks Oz.