Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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
 
Old January 12th, 2007, 10:28 PM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to DynaCube Send a message via AIM to DynaCube
Default Global.asa and user tracking

Hey Guys. Can someone help me out here? I'm working on my new site and I'm currently trying to integrate user tracking, but it's not working. I'm using global.asa to insert data into my Access database with the following code:


Code:
<OBJECT RUNAT=Server SCOPE=Session ID=BC PROGID="MSWC.BrowserType"></OBJECT>


<script language="vbscript" runat=server>

Sub Session_OnStart

    ' ADO Constants
    Const adOpenForwardOnly = 0
    Const adOpenKeyset = 1
    Const adOpenDynamic = 2
    Const adOpenStatic = 3

    ' LockTypeEnum Const Values
    Const adLockReadOnly = 1
    Const adLockPessimistic = 2
    Const adLockOptimistic = 3
    Const adLockBatchOptimistic = 4

'Define Data to Insert into Log

    'Sniff Browser Info From Header.
    Browser = Trim(Request.ServerVariables("HTTP_USER_AGENT"))

    'Get Users Browser Language Setting
    Language = _
        Trim(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE "))

    ' Where did they come from? Oh! That's Where!
    Referer = Trim(Request.ServerVariables("HTTP_REFERER"))
    SessionID = Trim(Session.SessionID)

    'Get User IP
    UserIP = Trim(Request.ServerVariables("REMOTE_HOST"))
    Session("IP") = UserIP

'What Part of the Site did they Hit First?
    FirstPage = Trim(Request.ServerVariables("Script_Name"))

'Resolve OS and Browser details if possible
    OS = bc.platform
    UA = bc.browser
    UAversion = bc.version
    Today = Now()

    'Log week and year number stats for later retrieval
    TWeekNumber = DatePart("ww", Now())
    TYearNumber = DatePart("yyyy", Now())

' Handle exceptions
    If Language = "" Then
        Language = "Unknown"
    End If

    If Referer = "" Then
        Referer = "None"
    End If

    'Could be useful to persist REFERER info.
    Session("Referer") = Referer

    BrowserCode = "0"
    Set oSRS = Server.CreateObject("ADODB.RecordSet")

    'DB Connection Settings
    strSConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("./db/DC1.mdb") & ";"
    strSQL = "SELECT * FROM tblSession"
    oSRS.CursorType = adOpenKeyset
    oSRS.LockType = adLockOptimistic

On Error Resume Next
    oSRS.Open strSQL, strSConn

    ' Update the DB with the Info.
    oSRS.AddNew
        oSRS("Browser") = Browser
        oSRS("Language") = Language
        oSRS("Referer") = Referer
        oSRS("SessionID") = Session.SessionID
        oSRS("UserIP") = UserIP
        oSRS("Date") = Date()
        oSRS("Time") = Time()
        oSRS("HitPage") = FirstPage
        oSRS("TWeekNumber") = TWeekNumber
        oSRS("TYearNumber") = TYearNumber
        oSRS("BrowserCode") = BrowserCode
        oSRS("OS") = OS
        oSRS("UA") = UA
        oSRS("UAversion") = UAversion
    oSRS.Update

    oSRS.Close
    Set oSRS = Nothing


    IF Err > 0 Then
        Response.Write Err.Number & " " & Err.Description
    End IF

End Sub

</script>

The sitelog.asp page follows:


Code:
<% Response.Buffer = False

    'Max Records to display per page
    iPageSize = 25
    'Double Quote
    Q = Chr(34)
    'Line Feed
    CR = vbCrLf

    'Check for first page
    If Request.QueryString("page") = "" Then
        iPageCurrent = 1
    Else
        'Not 1st page, grab page # From querystring
        iPageCurrent = CInt(Request.QueryString("page"))
    End If

    'Do we want to show Browser details? If so Click the checkbox.
    IF lCase(Request("ShowBrowserDetails")) = "on" Then
        strChecked = "Checked"
        ShowBrowserDetails = True
    Else
        strChecked = ""
        ShowBrowserDetails = False
    End IF
%>

<html>
<head>
<title>Dyna-Cube | Site Log</title>
<META Name="ROBOTS" Content="NOINDEX, NoFollow"

</head>

<body>
<%
    Set RS = Server.CreateObject("ADODB.RecordSet")
    Conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("./db/DC1.mdb") & ";"
    strSQL = "SELECT * FROM tblSession"

    on Error Resume Next
    RS.PageSize = iPageSize
    RS.CacheSize = iPageSize
    RS.CursorLocation = adUSeClient
    RS.Open strSQL, Conn, 3, 3

    'Total # of pages
    iPageCount = RS.PageCount


IF iPageCount = 0 Then
    Response.Write "No records found!"
Else
    ' Move to the selected page
    RS.AbsolutePage = iPageCurrent

    Response.Write "Page <B>" & iPageCurrent & "</B> of " _
        & "&nbsp;<B>" & iPageCount & "</B>&nbsp;&nbsp;&nbsp;" _
        & RS.RecordCount & " Total Records." & vbCrLf


%>
<Form Method="POST" Name="frmShowMoreDetails">
Show Browser Details?
    <input type="checkBox" name="ShowBrowserDetails"
    <%= strChecked %>
    onClick="document.frmShowMoreDetails.submit()">
</form>

<table border=0 width="100%" cellspacing="4" cellpadding="4">
<tr bgColor="skyBlue">

<td valign="top">Referer</td>
<td valign="top" width="20%"><b>IP Address</b></td>
<td valign="top"><b>Date</b></td>
<td valign="top"><b>Time</b></td>
<td valign="top"><b>First Page</b></td>
<% IF ShowBrowserDetails = True Then %>
    <td valign="top"><b>Browser</b></td>
    <td valign="top"><b>Version</b></td>
<% End IF %>

</tr>

<%
    'counter to keep track of record #'s displayed
    iRecordsShown = 0
    'Loop thru records until Page Size is reached
    Do While iRecordsShown < iPageSize AND Not RS.EOF
    IF RS("Referer") = "None" Then
        strRef = "<b>Bookmark</b>"
    Else
        strRef = "<a href=" & Q & "#" & Q & " onClick=" & Q _
            & "var j = window.open('" & RS("Referer") _
            & "', 'newWin'); j.focus();" & Q & ">" _
            & urlDecode(RS("Referer")) & "</a>"
    End IF
%>

<tr bgColor="silver">
    <td valign="top" width="20%" WRAP=HARD><%= strRef %></td>
    <td valign="top"><b> <%= RS("UserIP") %></b></td>
    <td valign="top"><b> <%= RS("Date") %></b></td>
    <td valign="top"><b> <%= RS("Time") %></b></td>
    <td valign="top"><b> <%= RS("HitPage") %></b></td>
<% IF ShowBrowserDetails = True Then %>
    <td valign="top"><b> <%= RS("Browser") %></b></td>
    <td valign="top"><b> <%= RS("UAversion") %></b></td>
<% End IF %>
</tr>

<%
    RS.MoveNext
        'increment counter
        iRecordsShown = iRecordsShown + 1
    Loop

End IF

    RS.Close
    Set RS = Nothing

    Response.Write "</table>"

    IF iPageCurrent > 1 Then
       Response.Write "<input type=button " _
          & "name=" & Q & "btnPrev" & Q & " " _
          & "value=" & Q & "<< Previous " & Q & " " _
          & "onClick=" & Q & "window.location='SiteLog.asp?page=" _
          & iPageCurrent - 1 & "'" & Q & ">" & vbCrLf
    End IF

    If iPageCurrent < iPageCount Then
       Response.Write "<input type=button " _
          & "name=" & Q & "btnNext" & Q & " " _
          & "value=" & Q & "Next >>" & Q & " " _
          & "onClick=" & Q & "window.location='SiteLog.asp?page=" _
          & iPageCurrent + 1 & "'" & Q & ">" & vbCrLf
    End IF

' Function to help make the referer data a little more readable.
' Replaces urlEncoded data with it's original character
Function urlDecode(str)

    str = Replace(str, "%3F", "?")
    str = Replace(str, "%2F", "/")
    str = Replace(str, "%7C", "|")
    str = Replace(str, "%5C", "\")
    str = Replace(str, "%21", "!")
    str = Replace(str, "%40", "@")
    str = Replace(str, "%23", "#")
    str = Replace(str, "%24", "$")
    str = Replace(str, "%25", "%")
    str = Replace(str, "%5E", "^")
    str = Replace(str, "%26", "&")
    str = Replace(str, "%2A", "*")
    str = Replace(str, "%28", "(")
    str = Replace(str, "%29", ")")
    str = Replace(str, "%7B", "{")
    str = Replace(str, "%7D", "}")
    str = Replace(str, "%3A", ":")
    str = Replace(str, "%2E", ".")
    str = Replace(str, "%2D", "-")
    str = Replace(str, "%5B", "[")
    str = Replace(str, "%5D", "]")
    str = Replace(str, "%2C", ",")
    str = Replace(str, "%3D", "=")
    str = Replace(str, "%2B", "+")
    str = Replace(str, "%2D", "-")
    str = Replace(str, "%5F", "_")
    str = Replace(str, "%7E", "~")
    str = Replace(str, "%60", "`")
    str = Replace(str, "%27", "'")
    str = Replace(str, "%22", Chr(34))

    urlDecode = str
End Function

%>

I don't get any errors when I visit the site I'm working on but it doesn't insert a record either. I know the connection string is correct because it works fine for my login. Anyone have any ideas what I'm doing wrong?

Thanks to any and everyone who can help at all.
 
Old January 12th, 2007, 11:24 PM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to DynaCube Send a message via AIM to DynaCube
Default

I got it fixed guys. I just had to set my permissions to write on the directory that held my DB.

Thanks.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Global.asa pushpa Classic ASP Basics 19 March 9th, 2007 08:30 AM
About Global.asa pbcatan Classic ASP Databases 2 December 4th, 2006 12:40 AM
global.asa vin_0x1 Classic ASP Components 2 July 24th, 2006 01:13 AM
Global.asa madsmad ASP.NET 1.0 and 1.1 Basics 1 August 17th, 2003 07:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.