PDA

View Full Version : Redirection based upon hit counter variable


Bluefish21
04-15-2004, 01:00 AM
O.k. I'm a n00b, I'll admit it right off the bat. Now that that's established, here's what I'm trying to do. I want to rotate between 2 pages depending on whether the visitor has an "odd" last number or an "even" last number, which would be dictated by a hit counter. How can I pull just the last number off of the hit counter so that I can do this? Or is this even possible? This is what I've got so far. The hit counter I grabbed from a site, so I don't know if it's alright or not.

//Hit counter
<%
fp = Server.MapPath("aspcount.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(fp)
ct = Clng(a.ReadLine)
if Session("ct") = "" then
Session("ct") = ct
ct = ct + 1
a.close
Set a = fs.CreateTextFile(fp, True)
a.WriteLine(ct)
end if
a.Close
Response.Write ct
%>
//Page determiner
<%
If number == 1, 3, 5, 7 Then
Response.Redirect("sales1.html")
Else
Response.Redirect("sales2.html")
%>

That's all I got. Also, would I put this on page such as sales.asp and have whatever link I'm using to get to that page point to the sales.asp. Yeah, I would or how would it redirect the user?

raf
04-15-2004, 03:09 AM
woul be a lott easier to use an applicationvariable for this, and increment that + to use a MOD 2 to determine if it's even or not.
Like

application("counter") = application("counter") + 1
If application("counter") MOD 2 = 0 then 'even numbers
Response.Redirect("sales1.html")
Else
Response.Redirect("sales2.html")
End if

Bluefish21
04-15-2004, 03:43 AM
Thank you for your reply. This is what I've come up with.
This will be placed in the global.asa file

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

Sub Session_OnStart
'This line is only for IIS 4.0. Do not use the Lock
'function in IIS 5.0.
Application.Lock
Application("NumVisits") = Application("NumVisits") + 1
Application("datLastVisited") = Now()
'This line is only for IIS 4.0. Do not use the UnLock
'function in IIS 5.0.
Application.UnLock
End Sub

and this will go into the page

function OddOrEven(ByVal intNumber)
If (intNumber MOD 2 = 0 ) Then
Server.Transfer("sales1.html")
Else
Server.Transfer("sales2.html")
End If
end function

I had some help from an egghead on this, but I do believe that that'll do it. Thanks for the help. I've gotta go try it out now. :D