The Page Counter Component

Finally, you might want to get some idea of how frequently your page is being accessed without having to dig through the server logs. The Page Counter component enables you to do that with just a few lines of code. We can add this under the banner ad on index.asp with the code in Listing 3.31.

Code Listing 3.31. index.asp: Adding a hit counter
…
31:<A href="register.asp">
32:<IMG SRC="images/register.gif" BORDER=0 ALIGN="middle" ALT="Register"
HEIGHT="39" WIDTH="39">
33:Register</A> -- jump on board
34:<P>
35:<%
36:    set AdvObject = Server.CreateObject("MSWC.AdRotator")
37:    adHTML = AdvObject.GetAdvertisement("ads/AdRotatorSched.txt")
38:    Response.Write adHTML
39:%>
40:
41:<% set pageCount = Server.CreateObject("MSWC.PageCounter") %>
42:   This page has been accessed <%= pageCount.pageHit %> times.
43:
44:</BODY>
45:</HTML>

On line 41, we create the Page Counter object, pageCount, then on line 42 we use the <%= %> syntax to print out the count. The PageHit method actually increments the counter, adding 1 every time the page is hit. To retrieve the count without incrementing, we could have used pageCount.hits instead of pageCount.pageHit. You can also reset the value number of hits for this page using the Reset method, so the command would be pageCount.Reset.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.208.25